Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Event not firing in usercontrol inside usercontrol

Thread Tools

Event not firing in usercontrol inside usercontrol
Posts: n/a
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();
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 " +
//do something to control here

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

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Event not firing in usercontrol inside usercontrol ASP .Net Building Controls 1 12-11-2004 01:28 PM
Event not firing in usercontrol inside usercontrol ASP .Net Building Controls 0 12-10-2004 02:20 PM
Access a control inside an usercontrol from another control inside another usercontrol nail ASP .Net 0 09-15-2004 03:55 PM
Event not firing. Adding controls dynamically to UserControl nitin ASP .Net Building Controls 5 07-23-2003 09:18 PM
Event not firing.adding dynamic controls to Usercontrol. nitin khungar ASP .Net Building Controls 3 07-21-2003 02:17 PM