Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Event not firing in usercontrol inside usercontrol

 
 
vatech1993@yahoo.com
Guest
Posts: n/a
 
      12-10-2004
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...

 
Reply With Quote
 
 
 
 
vatech1993
Guest
Posts: n/a
 
      12-11-2004
I figured it out. When I assign an ID to the linkbuttons, if I remove
the this.UniqueID from the name everything works fine. I was adding
this to make sure I could have multiple controls of the same type on a
form. What I didn't realize was that the framework was doing the same
thing for me. I didn't even need to derive the class from
IPostBackEventHandler. I'm not sure when is the correct time to use it
so any suggestions on when is appropriate would be appreciated.

 
Reply With Quote
 
 
 
Reply

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 vatech1993@yahoo.com ASP .Net Building Controls 0 12-10-2004 02:21 PM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com 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



Advertisments