Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Link Buttons on the fly

Reply
Thread Tools

Link Buttons on the fly

 
 
Matt MacDonald
Guest
Posts: n/a
 
      06-12-2004
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.v sd</a>, which is not
right. Anybody have any suggestions on this? Thanks alot,

Matt


 
Reply With Quote
 
 
 
 
Matt MacDonald
Guest
Posts: n/a
 
      06-12-2004
BTW, using the "oncommand" attribute doesn't work either

"Matt MacDonald" <> wrote in message
news:%...
> 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.v sd</a>, which is not
> right. Anybody have any suggestions on this? Thanks alot,
>
> Matt
>
>



 
Reply With Quote
 
 
 
 
Robert Koritnik
Guest
Posts: n/a
 
      06-14-2004
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. }

"Matt MacDonald" <> wrote in message
news:#...
> 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.v sd</a>, which is not
> right. Anybody have any suggestions on this? Thanks alot,
>
> Matt
>
>



 
Reply With Quote
 
BR.ZD
Guest
Posts: n/a
 
      07-29-2004

Robert Koritnik wrote:
> *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 even
> handler
> via __doPostback...
>
> --
> RobertK
> { Clever? No just smart. }
>
> [/vbcol] *


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
“test what you fly and fly what you test” Lawrence D'Oliveiro NZ Computing 0 06-05-2009 02:06 AM
THE FLY & THE FLY II teem DVD Video 0 12-10-2005 09:31 PM
Link Buttons on the fly Matt MacDonald ASP .Net 4 06-14-2004 08:18 PM
To Fly or not to fly? Should I move from Mozilla 1.5 to T-bird andF-bird? Daniel Steinberg Firefox 7 11-06-2003 11:31 AM
To Fly or not to fly? Should I move from Mozilla 1.5 to T-bird andF-bird? Daniel Steinberg Firefox 5 11-05-2003 06:23 AM



Advertisments