Dynamically adding events to a page

O

Oddball

I am trying to create and add a number of ImageButtons to a page when a certain
event is called.

Not only am I suffering from my page running the "Page_Load" event three times, but I
can't seem to get my new buttons to fire their events.

http://www.adquiesco.com/ShowCollection.aspx?collection=4

As far as I can tell the problem has something to do with the point in the page
execution where events are wired up.

Because the "more images" buttons are created and added to the page during an
event call (unlike the piece images at the bottom which are added on Page_Load) their
events don't seem to fire.

I think I've coded myself into a knot here and I would be greatful for any advice that
you can give me about this problem.

For example - where SHOULD I be creating and adding new controls to a page, and if
it HAS to be during page load how do I know which button has been clicked. :S

--> Oddball


------------------------------------

Another unchecked rambeling brought to you by:

Oddball
joshua@bf#N0SP4M#wd.co.uk
 
S

Stefan

The easiest way is in the Init event. Add a handler to the Init event
and add your buttons there.

If you add them at a later event (Onload or even OnPrerender), the
buttons show up in your page, but your viewstate will be corrupted,
which is why your events don't fire on postback
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top