0

Scenario

I have a site where users can register for a course, I'm developing a new feature allowing existing students to login with an email & password and register using their previous details.

Architecture

Register.aspx contains an email and password textbox, a login button and a forgot password button. Completing the email and password and clicking the login button results in a cross-page postback to the login.aspx page. Clicking the forgot password button also results in a cross-page postback to the login.aspx page.

Knowing that PreviousPage will be an instance of the code behind class for the Register.aspx page how can I distinguish between the two events (Login/Forgot Password) in the Page_Load for the Login.aspx page?

Code Magician
  • 23,217
  • 7
  • 60
  • 77
Naeem Sarfraz
  • 7,360
  • 5
  • 37
  • 63
  • @M_M, Don't necessarily agree with the recent edit, why tag with forms? That maybe the solution you proposed but don't think it necessary to tag the question with it – Naeem Sarfraz Nov 11 '11 at 00:56
  • I gave this some thought on the retag. My main goal was to increase the profile of your question so you might get more answers. The original tags are a bit specialized and may not be visible to helpful folks who subscribe to broad tags like `asp.net`. You're clearly asking about `asp.net`, likely `webforms` since you were talking about code-behind pages which are less common in MVC. Generic html forms may be too broad, I agree. Since you didn't post any code I wasn't quite sure how you had implemented your forms so I wanted to err on the side of making your question more visible to SO users. – Code Magician Nov 11 '11 at 04:29

1 Answers1

0

Why not handle the button logic in the code behind then use transfer? That would be easiest as you would have two methods:

protected Login_Click(...)

and

protected ForgotPass_Click(...)

When you're using the cross-page posting, you lose some of the context. You could add that back, however, in the control definition e.g.

<asp:Button runat="server" Text="Login" PostBackUrl="~/login.aspx?cmd=login" />
<asp:Button runat="server" Text="Forgot Password" PostBackUrl="~/login.aspx?cmd=forgot" />

Which you can then read like this:

if(Request.Querystring["cmd"]=="forgot")
    ...
Code Magician
  • 23,217
  • 7
  • 60
  • 77