Event not firing in usercontrol inside usercontrol

V

vatech1993

I'm stumped on this problem. I've created a user control that
dynamically creates 5 linkbuttons in the CreateChildControls method.
Each of these child controls is linked to a commandeventhandler, has
command name and argument attached and is assigned a unique id. If I
use this control on a web form everything works fine, the event fires
as planned. However if I contain the control inside another user
control, the event on the linkbutton does not fire. The problem seems
to be tied to the line where the ID property is assigned. If this line
is commented out, the event fires off. Unfortunately I need each of
the linkbuttons to have a unique id so I can access them at the time of
the event. The code is as follows:

protected override void CreateChildControls()
{
for (int x=0;x<5;x++)
{
LinkButton lb = new LinkButton();
lb.Text = "Button " + x.ToString();
lb.ID = this.UniqueID + "lb" + x.ToString();
lb.Command += new CommandEventHandler(OnClick);
lb.CommandName = "Click";
lb.CommandArgument = x.ToString();
this.Controls.Add(lb);
lb.Dispose();
}
base.CreateChildControls ();
}
protected void OnClick(object sender, CommandEventArgs e)
{
LinkButton linkClicked = (LinkButton) this.FindControl(this.UniqueID
+ "lb" + e.CommandArgument.ToString());
this.Response.Write("You clicked button " +
e.CommandArgument.ToString());
//do something to control here
linkClicked.Dispose();
}

Any help would be greatly appreciated, I've been beating my head
against the wall for too long on this one...
 

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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top