Asp.net ViewState does not retain control style

I read that the viewstate in asp.net stores the values of control properties in postbacks . Let's say I have a page with a textbox

<asp:TextBox ID="fldFileId" runat="server"></asp:TextBox>

      

and then client side via javascript, I get the element reference and then set the border style

refToTextBox.style["border-style"] = "dashed";

      

After postback, the border style disappears and the text box returns to its original appearance. But looking at the properties for asp: TextBox in VS2010 there is a BorderStyle property for it. Is there a reason why this attribute is not persisted in view state?

+3


source to share


1 answer


Setting a value on the client side does not update the ViewState. You have to set the server side styling for the ViewState to persist it. Alternatively, you can:



  • Re-run JavaScript after postback.
  • Save the style in a cookie and use JavaScript to restore the style.
  • Find a JavaScript library to change the ViewState on the client side (not recommended).
+2


source







All Articles