Link to home
Start Free TrialLog in
Avatar of niceguy971
niceguy971

asked on

C# -state

I found some good info about ViewState at http://www.extremeexperts.com/Net/Articles/ViewState.aspx.  Below is an example (from above site) showing scenario where ViewState should be disabled for the textBox on the webform.

Can you please provide two or three other exampes showing that ViewState can be disabled for specific control on webform..and why it needs to be disabled ???

-------------
After loading the view state, the page reads client-side information through the Request object and uses those values to override most of the settings for the server controls. In general, the two operations are neatly separated and take place independently. In particular, though, the second operation—reading from Request.Form—in many situations ends up just overriding the settings read out of the view state. In this particular case the view state is only an extra overhead. For example consider the following case, we have one textbox in the page and a link button. If you are typing the some  values in to the textbox and the posting the page using linkbutton. After postback, value in the textbox is retained though you enable or disable the viewstate. In this case you shouldnt enable viewstate for this textbox. Viewstate value is overridden by request.form values, since loadpostdata fires after loadviewstate view event in the Page lifecycle.
------------------
Thanks

Avatar of kaufmed
kaufmed
Flag of United States of America image

Can you please provide two or three other exampes showing that ViewState can be disabled for specific control on webform
It's the same for all controls, but:

<asp:TextBox ID="TextBox1" runat="server" EnableViewState="false"></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label" EnableViewState="false"></asp:Label>
<asp:Table ID="Table1" runat="server" EnableViewState="false"></asp:Table>
<asp:Button ID="Button1" runat="server" Text="Button" EnableViewState="false" />

Open in new window


why it needs to be disabled
Read "The Role of ViewState" in this link: http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic9
Avatar of niceguy971
niceguy971

ASKER

So

1)  For  the Button control (when we do not change Text property ) it ALWAYS makes sense to Disable ViewState correct???

<asp:Button ID="Button1" runat="server" Text="Continue" EnableViewState="false" />

2) For the Label Control (which we use to Display the same text ) it ALWAYS makes sense to Disable ViewState correct???

<asp:Label ID="Label1" runat="server" Text="Please enter your Name" EnableViewState="false"></asp:Label>

Thanks
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks