How to keep the Text of a Read only TextBox after PostBack()? How to keep the Text of a Read only TextBox after PostBack()? asp.net asp.net

How to keep the Text of a Read only TextBox after PostBack()?


Another solution I found and easier one:

Add this to the Page Load method:

protected void Page_Load(object sender, EventArgs e){     TextBox1.Attributes.Add("readonly", "readonly");}


Have your other control store the value in a hidden field, and on postback, pull the value from the hidden field and push it into the textbox on the server side.


txtStartDate.Attributes.Add("readonly", "readonly"); on pageload in the best of the best solutions ,instead or Javascripts,hidden variables,cache,cookies,sessions & Caches.