ASP.NET - How to display javascript warning using C #?

I have a page containing a text box and a button, when the user clicks the submit button, I want to display a message based on the bool value.

I researched stackoverflow and tried the code in these questions: Displaying and redirecting an Asp.net Web form

But that did not work. I have the following code:

ClientScript.RegisterStartupScript(this.GetType(),"", "alert('message')", true); 

What code do I need to display a warning message?

+3
javascript c #
Feb 20 2018-12-12T00:
source share
2 answers

you 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); } 
+8
Feb 20 '12 at 17:37
source share

Use this apporch

  Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \n" + strErrorDesc + " .');</script>"); 
+2
Feb 22 '12 at 7:30
source share



All Articles