how to persist event handlers for dynamically created web controls

Discussion in 'ASP .Net' started by Dica, Jun 20, 2007.

  1. Dica

    Dica Guest

    i've got a script that loops through a dataset and creates dynamic web
    controls and event handlers:

    while (oDr.Read()){
    RadioButton oRb = new RadioButton();
    oRb.ID = oDr["id"].ToString();
    oRb.AutoPostBack = true;
    oRb.CheckedChanged += new

    once any of the resulting radio buttons are clicked, a postback fires and my
    web controls are gone as well as the event handlers upon the page reload.
    the fact that the web controls are now gone doesn't really matter in this
    particular case, but the event handlers themselves are also gone, so my
    script doesn't execute. i was considering throwing the dynamically created
    controls into a table, saving that to session, and recreating upon the page
    load, but i can't save the event handlers there. the other thing to do would
    be to rerun the sql statement that was responsible for creating the dataset
    in my pageLoad event, but that seems like a waste of resources.

    has anybody got a better way to deal with this kind of thing?

    Dica, Jun 20, 2007
    1. Advertisements

  2. Dica

    bruce barker Guest

    you should do the recreate in oninit not onload. nothing wrong with
    redoing the sql query. your other option is to cache the dataset in
    session, but if you are using sql for session (enterprise level site)
    then its not much quicker.

    -- bruce (
    bruce barker, Jun 20, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.