SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Button event won't trigger in dinamically loaded Custom Web Control.

    I have an User Control containing an switch that loads
    a control dynamically depending on what type of object I get.

    Let's say if I get an object of type SingleChoiceQuestion, then I would like to
    load my SingleChoiceRule control.

    The problem begins when I want to load my FreetextQuestion, then I load
    my FreetextRule control. The problem is here that my FreetextRule control
    contains an inner TextBox, DropDownList and a Button.

    When I click on the button I want to populate my DropDownList with a
    text item from the TextBox.

    How can I do this? I have tried a lot of things but my button never get it's
    event fired. One thing is that I need to load my controls in the
    PreRender event.

    Cheers,

    Sogeking

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dynamically creating controls is a complex issue; one that is best avoided.

    Your specific problem is probably that the dynamically created controls are not loaded during the Init or Load phases of the page lifecycle. When they are not; ASP.NET will not be able to "find" then and dispatch the events that they may have posted back with. This problem can be remidied by ensuring that the controls are loaded during the Load phase. If they are generated from a table in the database, simply make sure this is where they are inserted.

    If they are truly being inserted dynamically you need to record the fact that they were inserted in the page viewstate, read this viewstate during Load and recreate the controls based on this information.

    As you can see, this is rather complex and requires a good understanding of the page lifecycle.

    A simpler approach could be to always insert all of the possible controls for each "question", but simply hit the "Visible" switch (and perhaps even the "EnableViewState" switch to minimize viewstate pressure) for the irrelevant controls.


Bookmarks

Posting Permissions

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