HighTechTalks DotNet Forums  

- Dynamic controls question

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss - Dynamic controls question in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
nickname
 
Posts: n/a

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

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

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.


Reply With Quote
  #2  
Old   
Teemu Keiski
 
Posts: n/a

Default Re: - Dynamic controls question - 09-11-2006 , 03:14 PM






Hi,

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:

http://aspadvice.com/blogs/joteke/archive/2006/01/06/14568.aspx


--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


"nickname" <leodippolito (AT) gmail (DOT) com> wrote

Quote:
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
postback.

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

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.




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.