dynamic controls and viewstate?

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!
 
A

Axel Dahmen

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
 
A

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top