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

niceguy971Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
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
0
niceguy971Author Commented:
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
0
käµfm³d 👽Commented:
Any time you have programmatic changes to the state of one or more of your controls, those affected controls are the ones for which you would want to use ViewState. If you programmatically change the text of the button on a PostBack, then you would probably want that in ViewState. If the controls receive their text from the markup only (i.e. the text is static), then there is no need to add to the ViewState--the state for those particular controls is automatically restored by virtue of the instructions in the markup.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
niceguy971Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.