简体   繁体   中英

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

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.net 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?

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);
}

使用这个围裙

 Response.Write(@"<script language='javascript'>alert('The following errors have occurred: \n" + strErrorDesc + " .');</script>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM