how to persist event handlers for dynamically created web controls

D

Dica

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
System.EventHandler(this.clientRadioButton_click);
}

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?

tks
 
B

bruce barker

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 (sqlwork.com)
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top