Dynamic controls and viewstate

Discussion in 'ASP .Net' started by =?Utf-8?B?RGlmZmlkZW50?=, Mar 17, 2006.

  1. Hello All,

    I am trying to add dynamic controls onto my page and here is how I am doing
    that.

    I have a page which has a button called as "AddMoreControls" and in this
    button's event handler I am creating controls dynamically and adding them to
    a panel on the page. For example, if the button is clicked once, the page is
    posted back and the controls are added properly. However, if I click the
    "AddMoreControls" for the second time the previously added controls are gone.
    Does anyone know why the system is behaving in this way?

    I understand that the static controls are created during init() method and
    their viewstate is loaded properly. How does this work for dynamic controls?

    Thanks!!
    =?Utf-8?B?RGlmZmlkZW50?=, Mar 17, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?RGlmZmlkZW50?=

    Teemu Keiski Guest

    Hi,

    dynamic controls would need to be created on every request. E.g if you
    create them initially in a postback event such as button click, you'd need
    to recreate them on next Page loading so that they'd exist in the Controls
    collection. ViewState would work when you'd have dynamic control
    instantiation in order.

    Here's a few links I've blogged for the reference how to work with Dynamic
    controls
    http://aspadvice.com/blogs/joteke/archive/2006/01/06/14568.aspx

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


    "Diffident" <> wrote in message
    news:...
    > Hello All,
    >
    > I am trying to add dynamic controls onto my page and here is how I am
    > doing
    > that.
    >
    > I have a page which has a button called as "AddMoreControls" and in this
    > button's event handler I am creating controls dynamically and adding them
    > to
    > a panel on the page. For example, if the button is clicked once, the page
    > is
    > posted back and the controls are added properly. However, if I click the
    > "AddMoreControls" for the second time the previously added controls are
    > gone.
    > Does anyone know why the system is behaving in this way?
    >
    > I understand that the static controls are created during init() method and
    > their viewstate is loaded properly. How does this work for dynamic
    > controls?
    >
    > Thanks!!
    >
    Teemu Keiski, Mar 18, 2006
    #2
    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. Abel

    dynamic controls and viewstate?

    Abel, Jun 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    433
    Axel Dahmen
    Jul 1, 2003
  2. =?Utf-8?B?SmVycnkgU3BlbmNlcg==?=

    Viewstate and dynamic controls

    =?Utf-8?B?SmVycnkgU3BlbmNlcg==?=, Nov 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,887
    Steve C. Orr [MVP, MCSD]
    Nov 9, 2004
  3. John
    Replies:
    8
    Views:
    3,668
    contour
    Dec 1, 2008
  4. Ronald
    Replies:
    2
    Views:
    835
    Robbe Morris [C# MVP]
    Jan 17, 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:
    459
    Eidolon
    May 4, 2004
Loading...

Share This Page