EnableViewState="False" doesn't work?

  • Thread starter Thread starter matt del vecchio
  • Start date Start date
M

matt del vecchio

Hi,

Either this is a bug, or I'm missing something.. I have a webform that
uses viewstate to retain values for most of its text boxes. But a few
of them I want to always be reset on postback.

So, I thought the thing to do would be to disable the viewstate for
those items, like so:

<asp:TextBox ID="sku" runat="server" EnableViewState="False"/>

....however, this plain doesn't work. the form remembers that field
everytime it is posted back.

am i missing something else? i remember my instructor running into the
same problem during a training session once, and he thought it may be
a bug.


thanks,
matt
 
Matt the contents of textboxes is not controlled by viewstate.
ASP.NET is doing that.
You could use HTML controls instead of webcontrols or reset them in code.

Andrew
 
ok, i got it. viewstate doesnt control that, it's just ASP.NET
automatically uses the HTTP POST to see what the previous values were,
then plops them back in somewhere during the page re-creation (after a
postback). interesting.

thanks,
matt
 
Matt said:
ok, i got it. viewstate doesnt control that, it's just ASP.NET
automatically uses the HTTP POST to see what the previous values were,
then plops them back in somewhere during the page re-creation (after a
postback). interesting.

thanks,
matt

um, where did you get training that your instructor was confused...it's
a core piece of knowledge for someone who's training others :-)

yup, you figured it out. ASP.NET's magic is a combination of viewstate
and the HTTP POST values. It knows the POST values will be there, so it
doesn't store that stuff away in viewstate. Anything else it needs to
recreate the page that can never come back in the POST data is then
persisted to viewstate.....
 
May I know how to access this HTML POST value? I am
currently using HtmlInputFile but the value is lost after
every postback. Please advise.
 
Back
Top