all groups > asp.net webcontrols > october 2005 >
You're in the

asp.net webcontrols

group:

Dynamically Created Controls Not Firing Events


Dynamically Created Controls Not Firing Events Robert Sheppard
10/28/2005 9:44:02 AM
asp.net webcontrols:
I have been wrestling with this problem for a few days and need some input.
I have created a standard webform that contains a TEXTBOX, BUTTON and a
USERCONTROL. I want to be able to input information into the textbox and
then click the button and have a list of results come back from my database.
The User Control is responsible for outputing the results by accepting a
DataReader object and building a table to show the results.

Pretty simple.

Within this table of results I have a button (at the end of eacy row) that I
want to act as an 'Add' button in order to add the line item to a shopping
cart (or move to a detail screen). I originally was simply dynamically
building ImageButtons and assigning them each a uniqueid and then attaching
them to an event that would do whatever I needed to do for that item
(shopping cart, detail, whatever).

These events do not fire and instead a Postback is generated and the
dynamically attached event goes untouched. I know that performing all this
functionality inside of the Postback will work. I don't really want to do
that however since it makes other things I want to do on the page much more
difficult since I then have all this functionality in the postback that I
only want to execute when I want to create a new list.

This is a very simple concept that seems to have a very difficult solution
in DotNet. I have since found that simply using a hyperlink control and
building a url with my parameters will work but I would really like to find
a way to get this to work.

Any Ideas.

Shep

Re: Dynamically Created Controls Not Firing Events Prodip Saha
10/28/2005 2:30:15 PM
Robert,
I just added a new article on exactly what you are trying to accomplish and
it is done in the simpliest manner.

Read this article at- http://www.aspnet4you.com/Articles.aspx?ArticleID=5032

Thanks,
Prodip
www.aspnet4you.com

[quoted text, click to view]

AddThis Social Bookmark Button