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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top