Sunday, October 31, 2010

How to show client side message from Server Side Code?

File to be uploaded can't be more than 4 MB.

Protected Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error
        Dim ex As Exception
        ex = Server.GetLastError
        If TypeOf (ex) Is HttpException Then
            If ex.ToString.IndexOf("System.Web.HttpException: Maximum request length exceeded") > -1 Then
                Server.ClearError()
                Dim str As String = "<script type=""text/javascript""></script>"
                Dim sb As StringBuilder = New StringBuilder()
                sb.Append("<script>")
                sb.Append("alert(""Nothing DONE!!!\nUploaded File size should not exceed 4 MB. Please Delete Selected File.\nERROR: " + ex.Message + """);window.history.back();")
                sb.Append("</scri")
                sb.Append("pt>")
                Dim s As String = sb.ToString
                Page.RegisterStartupScript("test", sb.ToString())
            End If
        End If
    End Sub

No comments:

Post a Comment