Creating controls dynamically based on a dynamic control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

    Creating controls dynamically based on a dynamic control

    Hi,

    Can someone provide some information on how to create a control dynamically
    based on the contents of another dynamic control.

    In my experience, all dynamic controls must be created in the Initialize
    stage of an ASP.Net page life cycle. Because viewstate is not available in
    the initialization stage, I cannot get the value of the 1st dynamic control
    to create the second control.

    I think building a server control would resolve this issue, but I'm looking
    for something a little more straight forward.

    Does anyone have any suggestions?
  • Kostadin Kostov

    #2
    RE: Creating controls dynamically based on a dynamic control

    Create container control - for example Panel or Literal Control. Then on the
    server side add your dynamically created control like this:
    pnl.Controls.Ad d...

    Hope that helps!
    Regards,
    Kostadin Kostov

    "Matt" wrote:
    [color=blue]
    > Hi,
    >
    > Can someone provide some information on how to create a control dynamically
    > based on the contents of another dynamic control.
    >
    > In my experience, all dynamic controls must be created in the Initialize
    > stage of an ASP.Net page life cycle. Because viewstate is not available in
    > the initialization stage, I cannot get the value of the 1st dynamic control
    > to create the second control.
    >
    > I think building a server control would resolve this issue, but I'm looking
    > for something a little more straight forward.
    >
    > Does anyone have any suggestions?[/color]

    Comment

    • Matt

      #3
      RE: Creating controls dynamically based on a dynamic control

      I'm not sure how this will help. Both the panel and literal control are
      still populated based on viewstate, which is not available in the Initialize
      stage of the page life cycle.

      Maybe I wasn't clear with my question. I'm trying to figure out how to
      build a dynamic control based on the contents of another dynamic control.

      For example, let's say I have a dropdown box that is used to build a
      multitude of other controls on the page. This dropdown box is data bound and
      as such the information in the box is not available until after the
      LoadViewState stage. Unfortunately, I need to add my controls in the Init
      stage because my dynamically created controls need to be rebuilt from
      viewstate. If I add them in the Load stage, the viewstate information is
      lost. Can you see the catch 22 here?

      Comment

      Working...