Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display alert box in asp.net

Tags:

c#

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?

like image 959
user2236493 Avatar asked Jan 17 '26 18:01

user2236493


1 Answers

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);
}
like image 119
Win Avatar answered Jan 20 '26 06:01

Win



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!