开发者

Check sessions when redirecting pages in ASP.NET?

Here's the scenario: Page 1 has a text box that, if filled, will be the name of the session. It also has a button that will take you to Page 2 (when clicked).

Page 2 has a button as well that simply redirects you back to Page 1. But now, how do I show the sessi开发者_Go百科on name in Page 1's textbox?

I don't think I can use the Page_Load function as that'll "interfere" when you first visit Page 1.

Any advice would be much appreciated.

Thanks


Page1Button_Click ....
{
    Session["Text"] = this.textbox.Text;
    Response.Redirect ....
}

Page1_Load ...
{
    if (!Page.IsPostBack)
    {
         this.textBox.Text = Session["Text"] != null ? Session["Text"].ToString() : "";
    }
}


You could use something like this in page load, if I'm understanding your question.

textBox.Text = Session["myvalue"] != null ? Session["myvalue"].ToString() : "";


They are different pages, so they should have different Page_Load events.

The first time they post on Page 1, store the value they entered in the session. Then, any other time you are on Page 1, just look in the session to see if that value is stored. If it is, display it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜