- Dynamic controls question

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default - Dynamic controls question

    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 Guest

  2. Similar Questions and Discussions

    1. Dynamic Controls
      hi, Here's what I'm trying to do. A simple datagrid that is populated by a variable amount of data, which displays a different amount of rows. ...
    2. dynamic controls in asp.net....Please Help...
      Hello People, I would appreciate your responses on this. I am writing an asp.net web-application involving C#. I am actually building a test...
    3. Newbie - Dynamic Controls
      I am building a webpage that pulls what would have been an include file in ASP 3. Basically it is an HTML navigation bar. Instead of using an inc...
    4. Dynamic Controls - Still!
      Hi Jim Thanks for your help. I changed the table from an ASP.Net table to an HTML table. I am till having the problem of the control placed...
    5. Dynamic Controls using ParseControl
      Hello everybody, I am using xml and xslt to generate dynamic asp server controls on the page. What I do is I store the control type and their...
  3. #2

    Default Re: - Dynamic controls question

    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:

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


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


    "nickname" <leodippolito@gmail.com> wrote in message
    news:1157992583.672031.296730@m73g2000cwd.googlegr oups.com...
    >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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139