EnableViewState="False" doesn't work?

  • Thread starter matt del vecchio
  • 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
 
A

Andrew de la Harpe

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
 
M

Matt Del Vecchio

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
 
C

Craig Deelsnyder

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.....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top