Problem with Dynamically Creating Link Buttons

Discussion in 'ASP .Net Building Controls' started by Burak, Sep 18, 2003.

  1. Burak

    Burak Guest

    Hello,

    This is my code behind code for dynamic link button creation:

    strUrl = "<asp:LinkButton CommandName='Onet3_Cd'
    onfiltered='LinkButton_Command' runat='server' " & _
    "Text='" & rdrOnet3("ONET3_TITLE") & "'
    CommandArgument='" & rdrOnet3("ONET3_CD") & "' id='lb"
    & i & "'></asp:LinkButton>"

    Dim ctrl As Control =
    Page.ParseControl(strUrl.ToString())
    plcCategory.Controls.Add(ctrl) ' place holder on html page

    The link button shows up fine when I run this, but
    when I click on the link, it doesn't take me to

    Sub LinkButton_Command(ByVal sender As Object, ByVal e
    As CommandEventArgs)

    Dim strDesc As String
    strDesc = sender.text
    Response.Write(sender.text)
    End Sub

    I based my code on

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr\
    fsystemwebuiwebcontrolslinkbuttonclasscommandnametopic.asp

    The click works if I hard code the link button on the
    html page, but if I create it dynamically, the click
    does not take me to the above sub.

    Do you know how to fix this?

    Thanks,

    Burak
    Burak, Sep 18, 2003
    #1
    1. Advertising

  2. Burak

    BK Guest

    Burak,
    From what I understand, since you are creating the
    imagebutton dynamically you have to make sure that you add
    the imagebutton on every page load for your button_click
    event to work.So make sure what ever code you are adding
    to add the imagebutton dynamically is executed on every
    page load.

    Hope this helps
    BK

    >-----Original Message-----
    >Hello,
    >
    >This is my code behind code for dynamic link button

    creation:
    >
    >strUrl = "<asp:LinkButton CommandName='Onet3_Cd'
    >onfiltered='LinkButton_Command' runat='server' " & _
    >"Text='" & rdrOnet3("ONET3_TITLE") & "'
    >CommandArgument='" & rdrOnet3("ONET3_CD") & "' id='lb"
    >& i & "'></asp:LinkButton>"
    >
    >Dim ctrl As Control =
    >Page.ParseControl(strUrl.ToString())
    >plcCategory.Controls.Add(ctrl) ' place holder on

    html page
    >
    >The link button shows up fine when I run this, but
    >when I click on the link, it doesn't take me to
    >
    >Sub LinkButton_Command(ByVal sender As Object, ByVal e
    >As CommandEventArgs)
    >
    >Dim strDesc As String
    >strDesc = sender.text
    >Response.Write(sender.text)
    >End Sub
    >
    >I based my code on
    >
    >http://msdn.microsoft.com/library/default.asp?

    url=/library/en-us/cpref/html/frlr\
    >fsystemwebuiwebcontrolslinkbuttonclasscommandnametopic.asp
    >
    >The click works if I hard code the link button on the
    >html page, but if I create it dynamically, the click
    >does not take me to the above sub.
    >
    >Do you know how to fix this?
    >
    >Thanks,
    >
    >Burak
    >.
    >
    BK, Sep 19, 2003
    #2
    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. Fredrik Rodin

    Multiple dynamically added link buttons

    Fredrik Rodin, Jan 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    419
    Fredrik Rodin
    Jan 9, 2004
  2. Gopal Krish
    Replies:
    2
    Views:
    3,048
    Gopal Krish
    Oct 8, 2004
  3. Mark
    Replies:
    3
    Views:
    488
    Mark Rae
    Jan 8, 2007
  4. Amoril
    Replies:
    5
    Views:
    498
    Amoril
    Feb 21, 2007
  5. Plateriot
    Replies:
    3
    Views:
    1,533
    Plateriot
    Jul 4, 2008
Loading...

Share This Page