Groups | Blog | Home
all groups > asp.net webcontrols > june 2004 >

asp.net webcontrols : Link Buttons on the fly


Matt MacDonald
6/12/2004 4:02:53 PM
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

Matt MacDonald
6/12/2004 4:05:51 PM
BTW, using the "oncommand" attribute doesn't work either

[quoted text, click to view]

Robert Koritnik
6/14/2004 3:32:25 PM
When you create your lb object. Do this:

lb.Command += new CommandEventHandler(this.LinkButton_Command);

This will make the appropriate link between the event and the event handler
via __doPostback...

--
RobertK
{ Clever? No just smart. }

[quoted text, click to view]

BR.ZD
7/29/2004 9:35:40 AM

[quoted text, click to view]

Please help me, I have a similar problem:

I create dynamical template for Repeater and in this template I need t
use LinkButton, so the code is smth like this:

This is InstantiateIn method of the ITemplate interface

LinkButton lbEdit=new LinkButton();
lbEdit.ID="btnEdit";
lbEdit.CommandName="Edit";
lbEdit.CommandArgument="Edit";
lbEdit.Text="Edit";
lbEdit.Command += new CommandEventHandler(btnCommandEdit_Click);
container.Controls.Add(lbEdit);

But when I render the control LinkButon does not generate hre
attribute in the HTML. I do not understand why !!! I've assigne
Command event


-
BR.Z
-----------------------------------------------------------------------
Posted via http://www.mcse.m
-----------------------------------------------------------------------
View this thread: http://www.mcse.ms/message758961.htm
AddThis Social Bookmark Button