Adding dynamic LinkButton to dynamic table

G

Guest

I have scoured the web to no avail. Any post that resembles my problem has no
answer.

I have an asp table on my page. I add rows and cells to it at run time with
info provided from a database in a custom function. To one of those cells I
add a new LinkButton, then wire a command event handler to it, which calls
the custom function, thus bypassing any need to use IsPostBack.

When a user clicks on the link button, nothing happens. I ran it through
debug with breaks, and it doesn't even go through the event handler.

So I tried a brand new blank page, and put a single linkbutton on it with an
event handler and some test values. What I found disturbed me. The command
and argument values are not stored in the resulting html! I'm at a loss to
explain how a linkbutton works, but I feel this discovery is key to why mine
aren't working.

Anyone know why this happens? I'd really how linkbuttons work internally, so
that I can better plan solutions. Am I simply doing something wrong?

code:

private void create_table()
{
r = new TableRow();
c = new TableCell();
LinkButton lb = new LinkButton();
lb.ID = "lb_" + user_id;
lb.Text = user_company_name;
lb.CommandName = "SHOW_USER_DETAILS";
lb.CommandArgument = user_id;
lb.Command += new
System.Web.UI.WebControls.CommandEventHandler(this.lb_show_user_details_Command);
c.Controls.Add(lb);
r.Cells.Add(c);
table1.Rows.Add(r);
}
 

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

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top