Re: textbox's state does not persist if onTextChanged not defined

From: Craig Deelsnyder (cdeelsny_at_no_spam_4_meyahoo.com)
Date: 08/06/04


Date: Thu, 05 Aug 2004 22:50:38 -0500

On Fri, 6 Aug 2004 03:18:44 +0200, Henri <hmfireball@hotmail.com> wrote:

> Thanks for your help Fred,
> but it seems that this behavior is by design.
> Even with ViewState enabled, input fields' Value is never stored in it
> unless you want to know when Value changed (by defining the OnTextChanged
> attribute).
> Seems that I'll have to customize TextBox!
>

This is because ViewState only stores what .NET cannot get from the
request stream. When a form is submitted, the textboxes and other
controls attach their name,value pairs onto the request stream, so that is
where .NET reads the 'new values' for all controls from. .NET knows this
data will be there, so it doesn't duplicate it into ViewState (especially
since ViewState would not have the correct value, it's not modified on the
client, it's static content itself, so it doesn't 'know' what the user has
just entered or modified on the screen)

Think of ViewState as having anything that isn't normally in a form POST
request, such as the text value of labels, e.g.

BTW, EnableViewState is true on controls by default, which is why you
don't have to include it as an attribute on a control. When you view a
control's properties in the Properties Window, only those that are
modified from their default values (they'd then turn bold in that window)
are added as attributes in the .aspx by VS.NET. You can of course
manually add them in as well...

-- 
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


Relevant Pages

  • Re: ASP.NET application load time after some change
    ... The speed can also be affected by how much stuff is in viewstate. ... as Labels or Controls who have their value set in the Load event have no ... because the compiler only needs to compile it once. ... web.config) that can increase or decrease load time? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ASP.NET application load time after some change
    ... The speed can also be affected by how much stuff is in viewstate. ... controls such as Labels or Controls who have their value set in the Load ... because the compiler only needs to compile it once. ... load time takes, sometimes, three or four of minutes ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Problem with ViewState ?
    ... event after viewstate is applied before you make something invisible. ... For example, when adding controls dynamically, the ... System.Web.UI.Control.LoadViewStateRecursive(Object savedState) +484 ... System.Web.UI.Control.LoadChildViewStateByIndex(ArrayList childState) ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: viewstate big
    ... You mean that viewstate uses *one* hidden field. ... Other hidden fields don't hold StateBag information. ... dynamic changes to the properties of server controls? ... It appears you are persisting the state of the controls through the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Load Controls from Event?
    ... Instead using TextBox to store the value between postbacks ... it would be better to use viewstate, ... protected int QueryBoxCount ... You cannot move creation of the controls anywhere because ...
    (microsoft.public.dotnet.framework.aspnet)

Loading