Hi all

I am working on a server control that will be a basic "add to shopping cart" button. This button will be used anywhere from 0 to 75 times on one page ie on a search results page, you would get one button for each result.

The problem I am having is handling the events that the cart button raises. The way I have it now, since the buttons are added dynamically to the page, I have to manually attach the handler using the addHandler method. I do this by looping through the page controls and testing each controls type to see if it is one of my cart buttons. When I find a match, I attach the handler and point it at my pages "cartbutton_clicked" method. This works perfectly. My question is - is there a better way? I don't like the idea of having to loop through the page controls every single time to find the buttons. It will get worse when I need to have custom hyperlinks and other misc controls that will be created dynamically and for which I need to add event handlers. The list of controls to loop through gets longer and longer, and I am quickly looking at close to 200 calls to addHandler().

Am I doing this completely wrong? Any better ideas out there?

Any advice is appreciated!