Only first user control event fires.

J

Jason Chancellor

Fairly new to asp.net so I'm sure what I'm doing wrong is silly...

I have created a user control which contains its own buttons,
textboxes, etc... and handles its own events. If I add just one of
these to a page either dynamically or otherwise it works great.

The problem is if I try to dynamically create more than 1 of these
user controls on a page only the first user control's events will
fire. The other user controls appear on the page, but their buttons
don't do anything when clicked.

Here is my code where I dynamically create my user controls:

while (sqlData.Read())
{
aControl = (DirMainListingControl)this.LoadControl("DirMainListingControl.ascx");
aControl.ID = sqlData["listing_id"].ToString();
aControl.SelectSite = sqlData["select_site"].ToString();
aControl.Category = sqlData["category"].ToString();
aControl.Title = sqlData["title"].ToString();
aControl.Description = sqlData["description"].ToString();
aControl.ListingId = System.Convert.ToInt32(sqlData["listing_id"]);
aControl.Active = sqlData["active"].ToString();
aControl.DateAdded = (DateTime)sqlData["date_added"];

ListingsPlaceholder.Controls.Add(aControl);
}

So for example the first user control created when going through this
loop works great, but number 2 through ... appears, but its events
wont fire.

Anyone know what I am doing wrong?

Thanks!
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top