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!
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!