简体   繁体   中英

how to display alert box in asp.net

i have a registration page with a submit button.

i want to show an alert box when the "user clicks on the submit button" after which the "data entered by the user is inserted in the database."

int i = obj.IU_SubscriberMaster(0, txtFirstname.Text, txtLastname.Text, txtEmail.Text, txtPassword.Text);

        if (i > 0)
        {
            Call ErrorTrap("errormsg");
        }

this is where i want to show the alert. i used

    function alerts(str) {
    return false;
}

and than by creating a function errortrap

public void ErrorTrap(string str)
{
    if (!ClientScript.IsStartupScriptRegistered("alert"))
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);
    }
}

but it did not work

can anyone please help?

Regular Page

public void ErrorTrap(string str)
{
   Page.ClientScript.RegisterStartupScript(this.GetType(), "alert" + UniqueID, 
     "alert('" + str + "');", true);
}

Ajax Page

You need to use ScriptManager if you use ajax.

public void ErrorTrap(string str)
{
   ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert" + UniqueID, 
      "alert('" + str + "');", true);
}

alerts :

Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);

needs to be alert :

 Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + str + "');", true);

Did you mean for the javascript to be "alerts("+ str + "');" and not "alert(" + str + "');" ?

alerts should be alert . if you are using ajax, better use ScriptManager.

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