Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert message box

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?

like image 905
Ebikeneser Avatar asked Dec 26 '22 10:12

Ebikeneser


2 Answers

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 alerted text:

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

like image 157
paul Avatar answered Dec 28 '22 22:12

paul


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 );
like image 31
Adil Avatar answered Dec 28 '22 22:12

Adil