Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBox values on Viewstate?

textBox values across postback do NOT maintain in Viewstate.

http://msdn.microsoft.com/en-us/library/ms972976.aspx

When the ASP.NET Web page is posted back in the load postback data stage, the Page class sees that one of the posted back form fields corresponds to the IPostBackDataHandler interface. There is such a control in the hierarchy, so the TextBox's LoadPostData() method is invoked, passing in the value the user entered into the TextBox ("Hello, World!"). The TextBox's LoadPostData() method simply assigns this passed in value to its Text property. the values are identified via posted back form field values, and assigned in the LoadPostData() method for those controls that implement IPostBackDataHandler.

Now lets talk about TextBox.OnTextChanged Method

It says there that:

Note

A TextBox control must persist some values between posts to the server for this event to work correctly. Be sure that view state is enabled for this control.

Question:

So I guess that for certain events, it does write to the Viewstate...

How does it tell ASP.NET to "Start tracking changes into the Viewsstate"?

like image 242
Royi Namir Avatar asked Aug 31 '26 15:08

Royi Namir


1 Answers

When you enable ViewState for a TextBox, it will simply be saved there.


ASPX Page Example

 <asp:TextBox ID="tb" runat="server" EnableViewState="true"></asp:TextBox>

C# (Code-behind) Example

tb.EnableViewState = true;

Your quote talks about the fact that this value is not needed when restoring the Form on Postback.

So you can turn off ViewState for a TextBox and it will still retain its value. But OnChanged will not work.

like image 125
Henk Holterman Avatar answered Sep 03 '26 03:09

Henk Holterman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!