Message Alert

I am using label text to show a different status on the asp.net website.

eg. "Profile Updates", "Invalid Character", etc., however, would prefer to have a pop-up message box.

Here is what I tried -

string alert = ws.webMethod(TextBox1.Text); System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert(" + alert + ")</SCRIPT>"); 

However, when this leaves, the screen in IE just gets bigger and the message box is not displayed.

How can i achieve this?

+4
source share
4 answers

I would not advise doing this, it looks like you are creating a modal page loading dialog, which means that your page cannot continue processing until the user clicks OK.

However, your problem probably is the lack of quotes in the alert ed text:

System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('" + alert + "')</SCRIPT>");

+4
source

Use ClientScriptManager.RegisterClientScriptBlock instead of Response.Write

 string alert = ws.webMethod(TextBox1.Text); string script = "<SCRIPT LANGUAGE='JavaScript'>alert(" + alert + ")</SCRIPT>" Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptBlockName", script ); 
+3
source

I used this in my project, works great for me

  ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "MessageBox", "alert('message')", true); 
+2
source

you can use alert , or you can use jquery plugin like this and this . if you use jquery plugin you can customize the message box like change backColor or ...

+1
source

All Articles