3

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?

0

4 Answers 4

6

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

when I run the "Regular Page" one I notice that the alert happens before some of my positioning css on the menu items
1

alerts:

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

needs to be alert:

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

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.