SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Toronto
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing Events

    Hi, I am building a web application where I have two dropdownlists and two text fields that are build on runtime.
    requirement: On "More" button click , these controls had to be added.
    process: I have added a place holder in aspx page. In code behind I created a new panel for every click and added those four controls to the panel. Then I added the panel to the placeholder.
    I have stored the list of panel in the session and added on every page load so I will see the panels being added on the page. So far so good. Now I have added an even to one of the dropdown list. and all the dropdown lists will access one event ddl_SelectedIndexChanged(.....). I set the Autopostback property to true. Sitll the Event is not accessed when the dropdownlist index is changed! Is it because I have added the controls in the Panel and added the panel to the place holder? Please let me know how I can access the event the fired by the dropdownlist.

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are making this more complicated than nessecary. Just design a page with the controls already in place. Place the "more" controls in a panel which is initially set Visible="false". When the "more" button is clicked simply switch the value to true through code.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Toronto
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. I have already done that way where I created several panels and made it visible one after the one when user click "More" button. My question is I really want to find out how the events can be accessed that is attached to the controls in the panel when I dynamically add the panels into the place holder.

    thanks

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to attach the events using code after having created the controls dynamically.

    99% of the time someone asks about dynamically created controls they really don't need them. It is advanced stuff, and you have to keep an eye out for re-creating them correctly on each request to allow them to properly manage their own viewstate. Try throwing in a command button which does nothing at all but enforce a postback. Does the page still work when that button is pressed at random point during the flow?

    Usually you are better off using panels, multiviews and/or repeaters.

    Using the session for storing state associated with a single page is bad practice, especially if it is the state of a dynamically created controls. What if the user opens two windows/tabs using the same page? How and when do you delete the state from the session? What if the user aborts the flow and start over; will you serve a virgin page?

    If you absolutely must create controls dynamically the information about which controls were created should ultimately be stored in viewstate or the url; not in the session.


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
  •