[英]One aspx page, two cross-page postbacks
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. Register.aspx包含一个电子邮件和密码文本框,一个登录按钮和一个“忘记密码”按钮。 Completing the email and password and clicking the login button results in a cross-page postback to the login.aspx page.
完成电子邮件和密码并单击“登录”按钮将导致跨页面回发到login.aspx页面。 Clicking the forgot password button also results in a cross-page postback to the login.aspx page.
单击“忘记密码”按钮也会导致跨页面回发到login.aspx页面。
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? 知道
PreviousPage
将成为Register.aspx页的类背后代码的一个实例,如何区分Login.aspx页的Page_Load
的两个事件(登录/忘记密码)?
Why not handle the button logic in the code behind then use transfer? 为什么不处理后面代码中的按钮逻辑然后使用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 eg
您可以在控件定义中将其添加回去,例如
<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")
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.