Ask a Question related to ASP.NET Building Controls, Design and Development.
-
vatech1993@yahoo.com #1
Event not firing in usercontrol inside usercontrol
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...
vatech1993@yahoo.com Guest
-
Can we use a usercontrol inside a usercontrol
hi group can we use a usercontrol inside a usercontrol. i mean can we use <%Register tagprefix..... src=....ascx%> in an ascx file. thanks in... -
LoadViewState override not firing in UserControl
We're trying to get an override void LoadViewState to fire in a user control that has been added dynamically to the page. The SaveViewState seems... -
Event not firing. Adding controls dynamically to UserControl
I am adding controls to the UserControl dynamically and then loading the UserControl Dynamically.But I am facing problem with firing of click event... -
Event not firing.adding dynamic controls to Usercontrol.
I am adding controls to the UserControl dynamically and then loading the UserControl Dynamically.But I am facing problem with firing of click event... -
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack
a uscontrol test.ascx have a dropdownlist web control the dropdownlist's AutoPostBack property is set "true" but when i use... -
vatech1993@yahoo.com #2
Event not firing in usercontrol inside usercontrol
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...
vatech1993@yahoo.com Guest
-
vatech1993@yahoo.com #3
Event not firing in usercontrol inside usercontrol
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...
vatech1993@yahoo.com Guest
-
vatech1993 #4
Re: Event not firing in usercontrol inside usercontrol
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.
vatech1993 Guest
-
mglorian #5
Re: Event not firing in usercontrol inside usercontrol
Hello
I have the same problem, sorry that I can't help you
can you let me know if you solved it?
BTW, i am currently investigating if it may be that dynamic events of a
control need to be declared (or mapped) in the form.
thanks
[email]vatech1993@yahoo.com[/email] wrote:> *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... *
--
mglorian
------------------------------------------------------------------------
Posted via [url]http://www.codecomments.com[/url]
------------------------------------------------------------------------
mglorian Guest



Reply With Quote

