WebControls and sub controls... problem with FindControl... Why?

T

ThunderMusic

Hi,
I have a custom WebControl. I fire an event and send, as the EventArg,
another WebControl that contains sub controls (ParseChildren(true))... It
can contain anything, but I want to find one control... Let's say the
control I want to find is "myControl". So I call
e.theObject.FindControl("myControl"); It always returns null and I know the
name of the control is good (that's the ID I gave it, is it possible it has
changed because it's the child of a WebControl?). When I look at "theObject"
in the Watch window, I got to it's base (WebControl), the to the "Controls"
property, then to the non-public fields to find the collection of controls
it contains and I find my object with the name I want...

The question is... Is there a way for the FindControl function not to find a
control contained in the Controls collection? It's there for sure, why
FindControl does not find it?

thanks

ThunderMusic
 
T

ThunderMusic

somewhere on the net, I found this little method and guess what, my control
shows, but FindControl does not find it... Should I create my own
FindControl method?

here's the method I found :
private string IterateThroughChildren(Control parent)
{
StringBuilder sb = new StringBuilder();
foreach (Control c in parent.Controls)
{
if (c.UniqueID != null)
{
sb.Append("<li>" + c.UniqueID.ToString() + "</li>");
if (c.Controls.Count > 0)
{
sb.Append("<ul>");
sb.Append(IterateThroughChildren(c));
sb.Append("</ul>");
}
}
}
return sb.ToString();
}

thanks

ThunderMusic
 
T

ThunderMusic

finally I did my own FindControl method, but I want to know if there is a
better solution (or even a cause) to this...

thanks

ThunderMusic
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top