Submit form to asp.net

I have two buttons that both submit the form to asp.net.

I need to know in the function below. Which button was clicked. Login or registration button. And from this information, I want to call one of the functions in the load event.

    protected void Page_Load(object sender, EventArgs e)
{
    AddCountries();
    AddAge();

      if (IsPostBack)
      {
          string pwd = LoginPassword.Text;
          string saltAsBase64 = "z3llWdYSA2DY3M4uNSpOQw==";
          string hash = HashPass.GenerateHash(pwd, saltAsBase64);

          if (Page.IsValid)
          {
              LoginUser(hash);
         /// Depending on what the user pressed..I need to trigger the function 
        // above or below
              RegisterUser(hash);
          }



      }
}

What if I have this in a button event:

FormsAuthentication.RedirectFromLoginPage (currentUser.UserName, false);

will redirection occur immediately after the button event? or will it trigger the page load event again, ignoring this redirect?

+3
source share
1 answer

If the buttons are server-side controls <asp:button/>, you can handle the event of the (specific) button:

protected void Button1_Click(object sender, EventArgs e) {....}

against.

protected void Button2_Click(object sender, EventArgs e) {......}

Page_Load: ASP.Net

HTML <input type=submit /> , Request.Form ( ).

UPDATE:

  • Page_Load ,
  • , Page.IsValid , -.
  • / Page_Load ( Page.IsPostBack - ...

, ( ) Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack)
    {
        if ((UserEmail.Text == "jchen@contoso.com") &&
         (UserPass.Text == "37Yj*99Ps"))
          {
            FormsAuthentication.RedirectFromLoginPage
               (UserEmail.Text, Persist.Checked);
          }
        else
          {
            ......
          }
    }
}

, MSDN

UPDATE2:

, Page_Load. Page.IsValid.

+4

All Articles