dynamic controls and viewstate?

  • Thread starter Thread starter Abel
  • Start date Start date
A

Abel

Hello -

How can I utilize ViewState when my webform has dynamically generated
controls?

Is there a way to add/retrieve values to/from viewstate so that I can use
ViewState? I'd rather not have to manually "manage state" in my webforms
for persistant control values if there is a way to use ViewState for this.

Any suggestions/how-to's/advice?

Much appreciated - thanks in advance.

Cheers!
 
The way ASP.NET handles dynamically created controls is kind of a "hit & run". You *always* have to add your controls to the page in the Page_Load() event - even on postback. As soon as you did, you can retrieve their ViewState by iterating through the Controls[] tree.

HTH,
Axel Dahmen
 
The way you described it is exactly the way it works:

foreach (object oStr in Controls)
{
litPageParams.Text += oStr.Text + " | ";
}

Could you explain why this doesn't work for you?

Axel

----------------------------
Abel said:
Sorry if I sent this to you...I CTRL+R'd from OutlookExpress...

Have an example? How do I specify which control's viewstate to get?
Is there something like: Page.Control.GetViewState(ctlName)?

Something like this isn't working for me:
foreach (object oStr in Controls)
{

litPageParams.Text += oStr.ToString() + " | ";

}

The way ASP.NET handles dynamically created controls is kind of a "hit &
run". You *always* have to add your controls to the page in the Page_Load()
event - even on postback. As soon as you did, you can retrieve their
ViewState by iterating through the Controls[] tree.

HTH,
Axel Dahmen

----------------------------------
Abel said:
Hello -

How can I utilize ViewState when my webform has dynamically generated
controls?

Is there a way to add/retrieve values to/from viewstate so that I can use
ViewState? I'd rather not have to manually "manage state" in my webforms
for persistant control values if there is a way to use ViewState for this.

Any suggestions/how-to's/advice?

Much appreciated - thanks in advance.

Cheers!
 
Back
Top