passing data between pages asp.net
Im going to implment password reset functionality. First user enters email into the form. Then click submit. On the server side I check if开发者_Python百科 the email is correct and if the user exists in database and if so then I redirect to the next page (in fact it is the same page with questry string parameter ?step=2).
I cant use session because of loadBalancer. What is the best way to keep users mail ?
thanks for any help
If it is the same page then it should be fairly trivial. You could add a hidden input field and append it to your form so in your button click handler:
protected void Button1_Click(object sender, EventArgs e)
{
string email = email.Text;
//Check database etc
HtmlInputHidden hidden = new HtmlInputHidden();
hidden.Value = email;
hidden.ID = "hiddenemail";
form1.Controls.Add(hidden); // Where form1 is the ID of a form with runat=server
}
Or event better if there was an existing server control say a label that you could use you would just do:
protected void Button1_Click(object sender, EventArgs e)
{
string email = email.Text;
//Check database etc
Label1.Text = email; // Where Label1 is the ID of a ASP:Label on your page
}
If you do not want to use a Postback (for whatever reason) and cannot use Session, the only solution I see is to include the email in the querystring.
Response.Redirect("MyPage.aspx?step=2&email=" + Server.UrlEncode(emailaddr));
If it does not necessarily have to be a redirect, see James Hay's answer.
I honestly don't understand the issue here?
If you have the email in the Database that must mean you also have all the other information in the Database. So to skip all the reload page etc. then go ahead and use <asp:Panels>
or <asp:Views>
as the swap between visible=false/true have no requirement for a page-reloading postback.
Example
if(email == emailFromDB)
{
panelStep1.visible=false;
panelStep2.visible=true;
// Insert information into whatever controls you have in mind.
}
精彩评论