Link Buttons on the fly

Discussion in 'ASP .Net Web Controls' started by Matt MacDonald, Jun 12, 2004.

  1. 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, Jun 12, 2004
    #1
    1. Advertising

  2. 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.vsd</a>, which is not
    > right. Anybody have any suggestions on this? Thanks alot,
    >
    > Matt
    >
    >
     
    Matt MacDonald, Jun 12, 2004
    #2
    1. Advertising

  3. 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.vsd</a>, which is not
    > right. Anybody have any suggestions on this? Thanks alot,
    >
    > Matt
    >
    >
     
    Robert Koritnik, Jun 14, 2004
    #3
  4. Matt MacDonald

    BR.ZD Guest

    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
     
    BR.ZD, Jul 29, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt MacDonald

    Link Buttons on the fly

    Matt MacDonald, Jun 12, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    675
    Matt MacDonald
    Jun 14, 2004
  2. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    904
    Kevin Spencer
    May 17, 2005
  3. Roger
    Replies:
    1
    Views:
    655
    GreggTB
    May 20, 2005
  4. tshad

    Setting up buttons on the fly.

    tshad, Jul 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    458
  5. Brian

    Fly outmenu on the fly

    Brian, Apr 8, 2005, in forum: Javascript
    Replies:
    0
    Views:
    120
    Brian
    Apr 8, 2005
Loading...

Share This Page