Dynamically Added Link Buttons

foz

Freshman
Joined
Mar 2, 2004
Messages
34
Location
Ireland
Hi all,

I'm new to the board, everythings looks pretty cool!

The problem I'm having, as the title suggests, is with dynamically added linkbuttons.

I have a search functionality, that returns all results displayed in a asp:table via the table.rows.add(TableRow) etc...
For each record returned I'm adding a delete linkbutton and an edit linkbutton each with an ID relative to the record returned.

The problem is that the CommandEventHandlers that I've created aren't getting executed.

If I put the function that I created to run whenever the search button is clicked (i.e. the function that adds the delete and edit linkbuttons) into the Page_Load, then CommandEventHandlers created run fine.

Any Ideas? I think it has something to do with the lifecycle of webcontrols... but not 100%.

any ideas?

cheers,

foz
 
I have done something similar to this with one of my apps - so I might be able to help if I can see some of your code so I can see what you are doing...
 
which bits would you like?

here's how the link buttons are created:

// the below is encapsulated in a do{}while(sqlDR.Read());

// create the control and add to tablecell

tdDELETE = new TableCell();
lbDelete = new LinkButton();
lbDelete.ID = "lbDel"+i;
lbDelete.Text = "Delete";
lbDelete.CommandArgument = i.ToString();
lbDelete.CommandName = "Delete";
lbDelete.Command += new System.Web.UI.WebControls.CommandEventHandler(OnLinkClick);
lbDelete.Attributes.Add("onclick", "return confirm('Are you Sure you want to delete this?');");
tdDELETE.Controls.Add(lbDelete);

// then the table cell is added to the dynamically created tablerow
 
i figured it was this, cheers. I was just hoping someone would have had the same problem and come across a different solution.

i've ended up just putting the function that generates the tbl into the page_load and worked around this.

cheers,

kahlua
 
Back
Top