I have got two buttons, which both submit a form in asp.net.
I need to know in the function below..What button was clicked..The login or register button. And by that information, I want to trigger the 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 the button event:
FormsAuthentication.RedirectFromLoginPage(currentUser.UserName, false);
will the redirection happen immediately after the button event? or will it trigger the page load event again, ignoring that redirection?
If the buttons are server side controls
<asp:button/>then you can handle the event of the (specific) button:vs.
Which are raised after
Page_Loadsee: ASP.Net Page Life CycleIf you are using standard HTML
<input type=submit />and posting back to the same page, then you can inspect theRequest.Formcollection (which you can also do with server side controls).UPDATE:
Page_Loadis always raised on postbackPage.IsValidin the handler before executing somethingPage_Load(checking forPage.IsPostBack– the point is you have options…So if you (instead) wanted to inspect on
Page_Load:above code taken, and slightly modified, from MSDN
UPDATE2:
If you are using server validation controls, don’t use
Page_Load. Use the button handler and check forPage.IsValid.