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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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);
}
Method 2
alerts:
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);
needs to be alert:
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + str + "');", true);
Method 3
Did you mean for the javascript to be "alerts("+ str + "');" and not "alert(" + str + "');"?
Method 4
alerts should be alert. if you are using ajax, better use ScriptManager.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0