I have a page that contains a textbox and button, when the user clicks the submit button I want to display a message based on a bool value.
I have researched on stackoverflow and tried the code in this questions: Asp Webform Display Alert and redirect
But it didn't work. I have the following code:
ClientScript.RegisterStartupScript(this.GetType(),"", "alert('message')", true);
What code do I need to display the alert message?
I have a page that contains a textbox and button, when the user clicks the submit button I want to display a message based on a bool value.
I have researched on stackoverflow and tried the code in this questions: Asp Webform Display Alert and redirect
But it didn't work. I have the following code:
ClientScript.RegisterStartupScript(this.GetType(),"", "alert('message')", true);
What code do I need to display the alert message?
Share Improve this question edited May 23, 2017 at 12:24 CommunityBot 11 silver badge asked Feb 20, 2012 at 17:32 TheomaxTheomax 6,80015 gold badges55 silver badges73 bronze badges 2- Can you provide more information on what didn't work in the code from the question you referenced? – jeffa00 Commented Feb 20, 2012 at 17:41
- isn't that second parameter supposed to be the name of the updatepanel? maybe I'm thinking of another register script method... – Induster Commented Feb 22, 2012 at 7:38
2 Answers
Reset to default 8you can use this simple method:
private void MessageBox(string msg)
{
Label lbl = new Label();
lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
Page.Controls.Add(lbl);
}
Use this apporch
Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \n" + strErrorDesc + " .');</script>");