Handling Onclick Event from dynamically created linkbuttons (1.1)

R

RSH

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
 
R

rbg

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 = "(e-mail address removed)";
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");
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top