Custom Control question (using Master page)

Discussion in 'ASP .Net Web Controls' started by David Wier, May 14, 2008.

  1. David Wier

    David Wier Guest

    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?
    David Wier, May 14, 2008
    #1
    1. Advertising

  2. David Wier

    Stan Guest

    On 14 May, 18:31, "David Wier" <> wrote:
    > 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
    Stan, May 14, 2008
    #2
    1. Advertising

  3. David Wier

    Stan Guest

    On 14 May, 21:44, Stan <> wrote:
    > On 14 May, 18:31, "David Wier" <> wrote:
    >
    > > 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


    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
    Stan, May 14, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug McCann
    Replies:
    1
    Views:
    992
    William Brogden
    Aug 5, 2004
  2. Replies:
    1
    Views:
    3,190
    PeterKellner
    May 16, 2006
  3. Zeba
    Replies:
    1
    Views:
    480
    Mark Rae
    Feb 22, 2007
  4. Nathan Sokalski
    Replies:
    25
    Views:
    1,404
    Nathan Sokalski
    Mar 4, 2010
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,470
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page