Re: programmatically adding controls and ViewState

Adam Sills <[email protected]> Fri, 6 Jul 2007 15:55:36 -0500
Newsgroups gmane.comp.windows.devel.dotnet.web
Message-ID <[email protected]>
The actual composition of a page during every execution is loaded from the
ASPX contents. Anything you add dynamically in your codebehind must be
repeated every time the page loads.

If you want your dynamically added controls to have usable ViewState, you
have to add them to the page before the Load event (technically before
ViewState is loaded). An easy place to put it is inside Init.

Adam..


-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Smotritsky, Alex
Sent: Friday, July 06, 2007 3:39 PM
To: [email protected]
Subject: [DOTNET-WEB] programmatically adding controls and ViewState

This Microsoft page:



http://msdn2.microsoft.com/en-us/library/hbdfdyh7(VS.80).aspx



says:



If you insert dynamic controls between existing controls, the dynamic
control's view state information is inserted into the corresponding
location of the view state structure. When the page is posted and the
view state is loaded, the dynamic control does not yet exist; therefore,
the extra information in view state does not correspond to the right
control. The result is usually an error indicating an invalid cast.

A control I'm dynamically inserting is disappearing on postback. I think
that's because of the above mentioned issue. Is there a solution to
this?


===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com