We help IT Professionals succeed at work.

EnableViewState, how to override ViewState

Hawkeye6352 asked
I have an .aspx C# 2010 page.  It does everything I want it to.  Inserts records.  Updates records.  Only problem is.  When I close the form and come back to it, it loads the previous values into my asp:TextBoxes and asp:CheckBoxes.  I understand that if a viewstate is enabled for a data-bound control, the control will not be rebound when the page is reposted.  Instead the control's values will be restored from the view state.  I understand that to prevent this, you should do EnableViewState = false in the page directive, or in the <asp:whatever tag.  Problem is, this doesn't make any difference.  I have also tried to programmatically set the control's EnableViewState = false, and placed it in the Page_init and the Page_Load, with no luck.  How can I override the view state so that my control is populated from the database and not the view state when the form is opened?
Watch Question

Aaron JabamaniTechnical Architect

If you don't want asp:textbox feature, please use the html textbox control
Well, Textboxes do not use ViewState to maintain/hold their values between postbacks. Values are maintained in HTTP Post headers. Controls like Textbox, inherit from IPostBackDataHandler interface and that is what is responsible for this behaviour. http://www.dotnetfunda.com/articles/article760-common-misconception-regarding-viewstate-and-textbox.aspx

As APeter highlights, if you dont want this behaviour, you have to use the HTML Textbox control and not the ASP.NET Textbox control.
Christopher KileSenior Software Analyst

When you close the form and come back to it, it is showing you the same values as were present the last time you opened the form??  What do you mean when you say you "closed the form"?  Did you close Internet Explorer, or did you go to another page?