Link Buttons on the fly

M

Matt MacDonald

Hi everyone,
I'm have a table in my aspx page that has 1 row which will contain 0 or
more cells. Each cell will contain a link button. My code is something
like this:

Dim lb As New System.Web.UI.WebControls.LinkButton
lb.Text = row("filename")

lb.CommandName = "GetAttachment"

lb.CommandArgument = row("attachmentID")

lb.Attributes("onclick") = "LinkButton_Command"

Dim cell As New System.Web.UI.WebControls.TableCell

cell.Controls.Add(lb)

cell.Visible = True

tblAttachments.Rows(0).Cells.Add(cell)

Where row is a row from a datatable in a dataset. Everything works fine
except that the "onclick" attribute doesn't work. If i manually code a link
button into my form, then it works fine. The problem "I think" is how the
control is being rendered. When I manually code the link button like:
"<asp:linkbutton text="button" Oncommand="LinkButton_Command"
CommandName="GetAttachment" CommandArgument="95" Runat=server/>" it renders
like this:
<a href="javascript:__doPostBack('_ctl0','')">button</a>. But when I make
it like in the above code, It renders like this:
<a onclick="LinkButton_Command" runat="server"
href="javascript:__doPostBack('_ctl1','')">FFIS2.vsd</a>, which is not
right. Anybody have any suggestions on this? Thanks alot,

Matt

PS, using oncommand instead of onclick does work either
 
J

Jos

Matt said:
Hi everyone,
I'm have a table in my aspx page that has 1 row which will contain
0 or more cells. Each cell will contain a link button. My code is
something like this:

Dim lb As New System.Web.UI.WebControls.LinkButton
lb.Text = row("filename")

lb.CommandName = "GetAttachment"

lb.CommandArgument = row("attachmentID")

lb.Attributes("onclick") = "LinkButton_Command"
<snip>

This last line will add a client-side handler, not a server-side one.

Use

AddHandler lb.OnClick, AddressOf LinkButton_Command

instead.
 

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,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top