Hi,
Have you tried writing a recursive method to find the TOP parent control and
return it back to you? I have written a sample code which is belove. I have
not compiled or tried the code so please excuse me if it does not work fine
but I hope it can give you some ideas.
Usage:
Label container = GetTopParentLabel(childControl);
if (container =! null)
{
lblControlID.Text = container.ID;
}
Required function:
private Label GetTopParentLabel(Control childControl)
{
return GetTopParentControl(childControl) as Label;
}
private Label lastParentLabel = null;
private Control GetTopParentControl(Control childControl)
{
if (childControl.Parent == null)
return lastParentLabel;
if (childControl.Parent.GetType() == typeof(Label))
lastParentLabel = (Label)childControl.Parent;
return GetTopParentControl(childControl.Parent);
}
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
"gnewsgroup" <gn********@gmail.comwrote in message
news:ca**********************************@1g2000hs l.googlegroups.com...
In my user control, I would like to find a Label control in the parent
page (the page that uses my user control). I need to update that
Label.Text when something happens in the user control.
I don't want to go through the hassle of creating events in the user
control, and then let the parent handle the event.
What is the easiest way to find a control in the parent page? Right
now, I am simply manually traversing it from the user control up to
the parent page and print out the control ID until I find the one I am
looking for.
In other words, in the user control, I am looking for the control in
the parent page like this:
lblControlID.Text = this.Parent.Parent.Parent.ID.ToString();
until I have appended enough ".Parent" and get the control ID.
This is very stupid, any wise approach?
Thank you.