How to get child controls in <asp:Content?

V

Victor Rodriguez

I need a way to be able to retrieve child controls on a <asp:Content
></asp:Content> the way I used to using findcontrol("ControlID"), when ever
I've try I get nothing.

Where should I look?

thanks,

Vic
 
W

Walter Wang [MSFT]

Hi Victor,

It's because FindControl cannot find control recursively, it only find
controls directly beneath the parent control. You can use following
function to find controls recursively:

private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}

foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}

return null;
}

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hello Victor,

How are you doing on this issue, does Walters'suggestion helps you some?

BTW, if your code will be dedicated to some particular pages with similar
control structure, you can use the ASP.NET page's output trace to lookup
the control structure of each page. The output trace contains a control
tree in which you can find the position of each server control in the
entire page control structure. You can use the @Page directive to turn on
output trace:

<%@ Page ............... Trace="true" %>


#Reading ASP.NET Trace Information
http://msdn2.microsoft.com/en-us/library/kthye016.aspx

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top