- Dynamic controls question - 09-11-2006 , 11:36 AM
I have a Table in my page. I must load some webcontrols dynamically
into this table, after the click of a button. These dynamic controls
can fire events. They also must keep their viewstate (so I must add
them in the Init phase).
Ok... after the button is clicked I am able to load the dynamic
controls into the table without any problem. Since the page that hosts
everything can postback, I must rebuild these dynamically created
controls on each roundtrip, otherwise they won't be available after the
I am doing something like this:
1) button is pressed...
2) In the button click event handler I add the dynamic controls into
the table. Then I save into Session some custom-information needed to
rebuild the dynamic controls (such as the number of controls, their
ID's and their type).
Then the page is rendered with the dynamic controls visible to the
When the user does something that causes a postback, in the Init event
handler I restore the controls custom-information from Session and
rebuild them into the table again.
My question is: is there a better way to do this? It seems a bit
"hacky" to me... but I can't think of other way.
One more thing: is it possible to avoid the use of Session? It thought
of using ViewState, but it is not available on the Init phase. And I
can't add the dynamic controls in the Load phase, because I need to
keep viewstate for these dynamic controls (and the Load phase happens
after the LoadViewState method is called).
I appreciate any help and advice.
Re: - Dynamic controls question - 09-11-2006 , 03:14 PM
it depends on your case so much, but basically if it is question just adding
controls to a list ands keeping it etc, then maybe
some type of solution with existing databound contrtols like Repeater would
work. See my blog post:
ASP.NET MVP, AspInsider
"nickname" <leodippolito (AT) gmail (DOT) com> wrote
|Thread Tools||Search this Thread|