EnableViewState, how to override ViewState

Posted on 2012-08-13
Last Modified: 2013-01-11
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?
Question by:Hawkeye6352
    LVL 25

    Expert Comment

    If you don't want asp:textbox feature, please use the html textbox control
    LVL 30

    Accepted Solution

    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.

    As APeter highlights, if you dont want this behaviour, you have to use the HTML Textbox control and not the ASP.NET Textbox control.
    LVL 23

    Expert Comment

    by:Christopher Kile
    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?

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now