[thelist] (asp.net) accessing controls created at runtime.

Tab Alleman talleman at Lumpsum.com
Tue Feb 21 14:13:36 CST 2006


Thanks, I got it working now!

> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org]On Behalf Of James Conley
> Sent: Tuesday, February 21, 2006 12:21 PM
> To: peter at easylistbox.com; thelist at lists.evolt.org
> Subject: Re: [thelist] (asp.net) accessing controls created 
> at runtime.
> 
> 
> The contents of the dynamically created controls are indeed stored in
> viewstate.
> 
> The problem however comes into play onPost Back - the first thing
> ASP.Net tries to do is to "restore viewstate" - that is - take control
> information out of ViewState and put it into the contents of the
> control. If the control does not exist then the ASP.Net
> viewstate-restoration scheme fails. The solution is to create any
> dynamic controls either in Page_Init or Page_Load.
> 
> james c
> 
> 
> -----Original Message-----
> From: thelist-bounces at lists.evolt.org
> [mailto:thelist-bounces at lists.evolt.org] On Behalf Of Peter Brunone
> (EasyListBox.com)
> Sent: Tuesday, February 21, 2006 11:40 AM
> To: thelist at lists.evolt.org; thelist at lists.evolt.org
> Subject: Re: [thelist] (asp.net) accessing controls created 
> at runtime.
> 
> You're probably creating the controls *after* the click event handler.
> Dynamically added controls aren't automatically re-created on 
> postback,
> and they're not implicitly stored in Viewstate (or so I understand).
> 
> You'll need to add your controls a la
> Page.ViewState.Add("AttorneyFirstName", tbAttorneyFirstName) 
> so you can
> pick them up later.  Of course you could just use the Request.Form
> collection which has every form element from the posted page, but
> Viewstate is the common Microsoft answer (though I avoid it when
> possible).
> 
> HTH,
> 
> Peter
> 
> P.S.  If you want a more ASP.NET-specific list, consider
> http://groups.yahoo.com/group/AspNetAnyQuestionIsOK or some 
> of the other
> groups at http://www.aspfriends.com .  Not like you can't 
> post here, but
> you may get more specialized information there.
> 
> -- 
> 
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip Harvester 
> and archives of thelist go to: http://lists.evolt.org 
> Workers of the Web, evolt ! 
> 



More information about the thelist mailing list