Asp.net Session state Trying to keep contents of textbox when returned to page

ive two pages, one with a text box and a button, the other with a button a label. What i want to do is to display contents of the textbox on page 1, in the label of the page2 on button click. and then when i click the button to return to page1. preverse whats entered in the textbox on page1. sorry if its confusing. heres my code

page1.aspx

 protected void Button1_Click(object sender, EventArgs e)

 {      
 Session["fstName"] = txtBox.Text;
 Response.Redirect("Page2.aspx");
  }

page2.aspx

protected void Page_Load(object sender, EventArgs e)
    {
        string a = Session["fstName"].ToString();
        lblPage2.Text = a;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("WebForm1.aspx");
    }

Answers


Where do you set the value of the text box when returning to WebForm1.aspx? It should be very similar to what you have for the label on Page2.aspx. Something like:

protected void Page_Load(object sender, EventArgs e)
{
    string a = Session["fstName"].ToString();
    txtBox.Text = a;
}

At worst, you may need to wrap some error checking around it. Maybe something like:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
        if (Session["fstName"] != null)
        {
            string a = Session["fstName"].ToString();
            txtBox.Text = a;
        }
}

Need Your Help

How to pass the parameter of a function by object reference (C++)

c++ object boost reference

I want to pass the parameter of a function by object reference. If I write the code like this:

Count the occurrences of unequal numbers from a data frame

r distance

I have a data frame df with four columns. I would like to find the number of unequal number for each pair of rows.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.