views:

98

answers:

2

Put a textbox, a checkbox and a button on a website. Set the "EnableViewState" property of textbox and checkbox to false. Write something into textbox and check the checkbox. Click the button.

Why is the textbox still written and the checkbox checked after response?

+7  A: 

Some things aren't totally dependent on ViewState. In the controls you listed, those values are available in the POST sent to the server, so they're gotten out of there and the controls restore their state that way.

Other things, like the text in a <asp:Label> for instance aren't sent back in any way, and they'll lose their data without ViewState. The same is true for other properties, like the styling of the textbox, etc...only it's value will be restored, because that's all that's sent back and as a result, all it's coded to grab and restore. If you were to say make it red, that would be lost on postback.

As a general rule, what a control can restore strictly from posted data will be restored on postback, everything else is lost.

Nick Craver
A: 

Because Html Controls are State less control. There for Microsoft provide a feature Of ViewSate that help when user send the data into server or after post back the value remain same. There for You have to Enable the property "EnableViewState" to set true. By default all the asp.net controls enableviewstate is true

ricky roy
.... ?Excuse, me... what?
Artiom Chilaru
I already know them. That's why I said "Set the "EnableViewState" property of textbox and checkbox to false."
Ahmet Altun