getting child controls of a user control

D

darrel

I'm trying to create a custom 'summary validator'.

I want to walk through the validation controls on my ASCX page and then grab
the ones that are invalid.

So, I started with this to do the walkthrough:

for each cntrl as Control in Page.Controls
response.write (cntrl.GetType.ToString & "<br />")
next

The problem is that this only returns the controls on the parent .aspx
page...not the controls on the .ascx usercontrol page (the page with this
code). Is this simply a matter of different syntax or do I need to tackle
this a different way?

-Darrel
 
K

Karl

need to do this recursively:

sub Page_Load
WriteControls(Page)
end sub

private sub WriteControls(parent As Control)
for each child as Control in parent.Controls
if child.HasControls then
WriteControls(child0
end if
Response.Write(child.GetType.ToString() & "<br />")
end sub

karl
 
D

darrel

need to do this recursively:

Oh..DUH! Of course. That works great!

Ok, second question ;o)

I don't need to go through every control. Just this particular one
(contactForm.ascx). Is there a way only read through that specific control's
controls?

It seems that I should be able to call a specific control via index:

parent.controls(1)

but that doesn't seem to work, so I'm guessing I'm off on my syntax.

-Darrel
 
K

Karl

How is contactForm.ascx added?

programmatically?
dim c as control = Page.LoadControl("contactForm.ascx")
x.Controls.Add(c)

if so, you can just do:
WriteControls(c) where "c" is the control loaded above


or declaratively?
<uc:contactForm id="form" runat="server" />

if so, you should declare contactForm in your codebehind
protected contactForm as ContactForm 'assuming that's the typ

then in page_load or wherever
WriteControl(contactForm)

Karl
 

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

No members online now.

Forum statistics

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

Latest Threads

Top