dynamic controls and viewstate?

Discussion in 'ASP .Net' started by Abel, Jun 30, 2003.

  1. Abel

    Abel Guest

    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!
     
    Abel, Jun 30, 2003
    #1
    1. Advertising

  2. Abel

    Axel Dahmen Guest

    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" <> schrieb im Newsbeitrag news:uUV#...
    > 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!
    >
    >
    >
     
    Axel Dahmen, Jun 30, 2003
    #2
    1. Advertising

  3. Abel

    Axel Dahmen Guest

    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" <> schrieb im Newsbeitrag news:...
    > 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() + " | ";
    >
    > }
    >
    > "Axel Dahmen" <> wrote in message
    > news:%...
    > 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" <> schrieb im Newsbeitrag
    > news:uUV#...
    > > 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!
    > >
    > >
    > >

    >
    >
     
    Axel Dahmen, Jul 1, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmVycnkgU3BlbmNlcg==?=

    Viewstate and dynamic controls

    =?Utf-8?B?SmVycnkgU3BlbmNlcg==?=, Nov 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,896
    Steve C. Orr [MVP, MCSD]
    Nov 9, 2004
  2. John
    Replies:
    8
    Views:
    3,682
    contour
    Dec 1, 2008
  3. Ronald
    Replies:
    2
    Views:
    860
    Robbe Morris [C# MVP]
    Jan 17, 2006
  4. =?Utf-8?B?RGlmZmlkZW50?=

    Dynamic controls and viewstate

    =?Utf-8?B?RGlmZmlkZW50?=, Mar 17, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,243
    Teemu Keiski
    Mar 18, 2006
  5. Denny Smolinski via .NET 247

    Dynamic Controls, Placeholder, Retrieve Information from Dynamic Controls

    Denny Smolinski via .NET 247, May 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    485
    Eidolon
    May 4, 2004
Loading...

Share This Page