Problem with Dynamically Creating Link Buttons

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Problem with Dynamically Creating Link Buttons

    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

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr\[/url]
    fsystemwebuiwebcontrolslinkbuttonclasscommandnamet opic.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 Guest

  2. Similar Questions and Discussions

    1. Problem with creating External Link
      Hi, In Contribute 3.1 - I cannot create an external link to this address: ...
    2. Security problem when dynamically creating directories
      I am trying to dynamically create directories in my ASP.NET application (I am using Server.MapPath("/")+"test" as the folder) and I am getting a...
    3. Dynamically creating buttons per row: how?
      I'm working on a web application that will use some datagrid and asp.net, an asp.net Forum to be exact where people can leave posts and respond to...
    4. Dynamically creating buttons in custom datagrid control
      Hi, I am creating a custom control datagrid. For each dynamically created column I've added a button in the header that will filter based on the...
    5. Creating onClick event for dynamically (programatically) created buttons
      Hello all! My question is the following: I add buttons (server controls) programatically into a table cell. Example: Dim btObnovi As Button =...
  3. #2

    Default Problem with Dynamically Creating Link Buttons

    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
    >
    >[url]http://msdn.microsoft.com/library/default.asp?[/url]
    url=/library/en-us/cpref/html/frlr\
    >fsystemwebuiwebcontrolslinkbuttonclasscommandname topic.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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139