title: Preserve value of textbox using View State in Asp.net?
body: <p>I've a button and a textbox. I want a value to be entered in textbox and when I click on button the page will reload but the value should still be in the textbox. How can I do that. The following code doesn't work</p>
  
  <pre><code>namespace WebApplication2
  {
      public partial class _Default : System.Web.UI.Page
      {
  
          protected void Page_Load(object sender, EventArgs e)
          {
              if (!Page.IsPostBack)
              {
                  if (ViewState["value"] != null)
                  {
                      TextBox1.Text = ViewState["value"].ToString();
                  }
              }
          }
          protected void Button1_Click(object sender, EventArgs e)
          {
              ViewState["value"] = TextBox1.Text;
              Response.Redirect("default.aspx");
          }
      }
  }
  </code></pre>