Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamically adding events to a page

Reply
Thread Tools

Dynamically adding events to a page

 
 
Oddball
Guest
Posts: n/a
 
      08-03-2005

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/ShowCollect...x?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
 
Reply With Quote
 
 
 
 
Stefan
Guest
Posts: n/a
 
      08-04-2005
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

 
Reply With Quote
 
 
 
 
Stefan
Guest
Posts: n/a
 
      08-04-2005
Alternatively, if you need to add controls dynamically at a later event
check out another approach at
http://www.denisbauer.com/ASPNETSamples.aspx

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically adding controls with events (but events are not firing) SevDer ASP .Net 2 11-13-2007 06:33 AM
Dynamically adding onmouseover, onmouseout events not working Steve Macleod Javascript 2 05-20-2006 07:01 PM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
Adding events dynamically David Javascript 19 07-20-2005 05:49 PM
Adding events to dynamically created controls JezB ASP .Net 2 06-18-2004 02:54 PM



Advertisments