Professional Web Applications Themes

Dynamically add linkbuttons and wire them to same event?? - ASP.NET Building Controls

Hi, How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample? Many thanks, Linda...

  1. #1

    Default Dynamically add linkbuttons and wire them to same event??

    Hi,

    How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample?



    Many thanks,

    Linda


    Linda Guest

  2. #2

    Default Re: Dynamically add linkbuttons and wire them to same event??

    Hi Linda,

    If their events are not firing then I'm guessing you may be adding them too late in the execution lifecycle. At which point are you adding them? Also any short sample code you could provide will greatly help the guessing game.

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    [url]http://obies.com/vga/blog.aspx[/url]

    To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
    "Linda" <lindado-not-spam.com> wrote in message news:%23JH4qiLLEHA.3808TK2MSFTNGP12.phx.gbl...
    Hi,

    How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample?



    Many thanks,

    Linda


    Victor Garcia Aprea [MVP] Guest

  3. #3

    Default Re: Dynamically add linkbuttons and wire them to same event??

    Linda,

    You have to add an event handler to the control that you added
    dynamically. For the below example code I created a new ASP.NET
    project and placed a PlaceHolder control on the form.

    In the Page_Load event place the following code:

    'Instance a link button
    Dim MyLinkButton As New LinkButton

    'Set the text
    MyLinkButton.Text = "Click Here for Google"

    'Dynamically add to Place Holder
    PlaceHolder1.Controls.Add(MyLinkButton)

    'Add an event handler to button
    AddHandler MyLinkButton.Click, AddressOf HandleMyLinkButtonClick


    Then create a sub (delagate) to handle the click. It must have the
    parameters as in the example. This example redirects to Google.

    Sub HandleMyLinkButtonClick(ByVal sender As Object, ByVal e As
    System.EventArgs)
    Response.Redirect("http://www.google.com")
    End Sub


    If you have multiple links pointing to the same Handler you could use
    something like the following to determine which link was clicked:

    SelectedItemText = CType(sender, LinkButton).Text


    Hope that helps.


    On Tue, 27 Apr 2004 17:35:10 -0700, "Linda" <lindado-not-spam.com>
    wrote:
    >Hi,
    >
    >How do I dynamically add linkbuttons and wire them to same event? I am able to add linkbuttons but they do not fire the event. Does anybody have a working sample?
    >
    >
    >
    >Many thanks,
    >
    >Linda
    Robert Verderber Guest

Similar Threads

  1. dynamic linkbuttons event not raising - newbie
    By Matias Woloski in forum ASP.NET Building Controls
    Replies: 3
    Last Post: October 23rd, 01:48 AM
  2. Replies: 5
    Last Post: February 18th, 08:28 AM
  3. How to Raise Event dynamically?
    By TamaHina in forum ASP.NET Building Controls
    Replies: 2
    Last Post: October 9th, 02:44 PM
  4. Dynamically bound function to event
    By Bish in forum Microsoft Access
    Replies: 0
    Last Post: July 31st, 07:10 PM
  5. Replies: 0
    Last Post: July 28th, 11:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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