N
nickname
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.
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.