I have been using label text to show different status in an asp.net website.
e.g. "Profile Updates", "Invalid Character" etc, however would prefer to have a pop up message box instead.
This is what I have tried -
string alert = ws.webMethod(TextBox1.Text);
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert(" + alert + ")</SCRIPT>");
However when this is fired, the screen in IE just seems to get bigger, and no message box is presented.
How can I achieve this?
I would not advise doing this, it looks like you are creating a modal dialog on page load, meaning that your page cannot continue processing until a user has clicked OK.
That said, however, your problem is probably a lack of quotes around the alert
ed text:
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('" + alert + "')</SCRIPT>");
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 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With