Handling Onclick Event from dynamically created linkbuttons (1.1)

Discussion in 'ASP .Net' started by RSH, Apr 23, 2007.

  1. RSH

    RSH Guest

    Hi,

    I have a page that is generating Linkbuttons dynamically. I need to
    dynamically wire up the buttons to an OnClick handler server side.

    I am using this code but they are not firing the event.

    What am i missing?

    Dim ctrl As New LinkButton

    ctrl.CommandName = "LoadUser"

    ctrl.CommandArgument = dtrReader("EmailAddress") & ""

    ctrl.Text = dtrReader("FullName")

    AddHandler ctrl.Click, AddressOf LoadUser

    PlaceHolder1.Controls.Add(ctrl)



    Private Sub LoadUser(ByVal sender As Object, ByVal e As System.EventArgs)

    .....

    End Sub

    Thanks,
    Ron
     
    RSH, Apr 23, 2007
    #1
    1. Advertising

  2. RSH

    rbg Guest

    I just verified and the Event definately does fire:

    Here is the C# version of the code:

    LinkButton ctrl = new LinkButton();
    ctrl.CommandName = "LoadUser";
    ctrl.CommandArgument = "";
    ctrl.Text = "LoadUser";
    ctrl.Click +=new EventHandler(ctrl_Click);
    this.PlaceHolder1.Controls.Add(ctrl);

    private void ctrl_Click(object sender, EventArgs e)
    {
    Response.Write("You just clicked the LinkButton named LoadUSER");
    }
     
    rbg, Apr 23, 2007
    #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. Hrvoje Vrbanc
    Replies:
    1
    Views:
    471
  2. Replies:
    7
    Views:
    12,494
  3. msimmons
    Replies:
    0
    Views:
    544
    msimmons
    Jul 16, 2009
  4. Linda

    Dynamically add linkbuttons and wire them to same event??

    Linda, Apr 28, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    151
    Robert Verderber
    Apr 28, 2004
  5. Jim Mitchell

    Accessing OnClick event for dynamically created controls.

    Jim Mitchell, Aug 12, 2003, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    231
    Jim Mitchell
    Aug 13, 2003
Loading...

Share This Page