Custom Control question (using Master page)

D

David Wier

Using my custom control, I need to locate controls in the Content
section - - I know that I can do something like:

If (ctrl Is Nothing And Not page.Master Is Nothing) Then
ctrl = page.Master.FindControl("Content").FindControl(id)
End If

However, this only works if the ContentPlaceholder is actually named
"Content" - - how can I look through any ContentPlaceholder on the page, no
matter what it's ID is?
 
S

Stan

Using my custom control, I need to locate controls in the Content
section - - I know that I can do something like:

If (ctrl Is Nothing And Not page.Master Is Nothing) Then
ctrl = page.Master.FindControl("Content").FindControl(id)
End If

However, this only works if the ContentPlaceholder is actually named
"Content" - - how can I look through any ContentPlaceholder on the page, no
matter what it's ID is?

This question and the sample code is not making any sense. Any control
on a content page can be referenced directly from within that page no
matter what ContentPlaceHolder it is in.

Please clarify
 
S

Stan

This question and the sample code is not making any sense. Any control
on a content page can be referenced directly from within that page no
matter what ContentPlaceHolder it is in.

Please clarify

Sorry, forget that last post. On re-reading I can see you are trying
to write a generic method for a custom control to reference another
control (with a particular id) on the host page which may or may not
be a content page. The FindControl method returns immediate Child
controls but not controls within controls - if you see what I mean -
hence your problem and the need for an explicit reference to a known
instance of a ContentPlaceHolder (named "Content").

I think the answer is to iterate through the controls collection on
the master page and identify the ContentPlaceHolders using the
GetType() method for each for each control.

HTH
 

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,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top