- Dynamic controls question

Discussion in 'ASP .Net Building Controls' started by nickname, Sep 11, 2006.

  1. nickname

    nickname Guest

    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.
    nickname, Sep 11, 2006
    #1
    1. Advertising

  2. nickname

    Teemu Keiski Guest

    Hi,

    it depends on your case so much, but basically if it is question just adding
    controls to a list ands keeping it etc, then maybe
    some type of solution with existing databound contrtols like Repeater would
    work. See my blog post:

    http://aspadvice.com/blogs/joteke/archive/2006/01/06/14568.aspx


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


    "nickname" <> wrote in message
    news:...
    >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.
    >
    Teemu Keiski, Sep 11, 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. =?Utf-8?B?VGVyb3M=?=

    Dynamic Variables? OR Dynamic Controls

    =?Utf-8?B?VGVyb3M=?=, Aug 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    412
    Scott Allen
    Aug 10, 2004
  2. Replies:
    5
    Views:
    5,553
  3. Ronald
    Replies:
    2
    Views:
    811
    Robbe Morris [C# MVP]
    Jan 17, 2006
  4. =?Utf-8?B?U3RldmUgRnVuaw==?=

    Dynamic Wizard with Dynamic Validation Controls

    =?Utf-8?B?U3RldmUgRnVuaw==?=, Oct 13, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    434
    =?Utf-8?B?U3RldmUgRnVuaw==?=
    Oct 13, 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:
    450
    Eidolon
    May 4, 2004
Loading...

Share This Page