Access property and control of master page from a customized parent page class

Discussion in 'ASP .Net' started by RedHair, Mar 22, 2006.

  1. RedHair

    RedHair Guest

    I have a ASP.NET 2.0 web page which inherits a customized base page class
    and have a master page,
    their relation is as below

    Customized base page class --> web page --> master page

    How to access the property and control of master page from the customized
    base page class?

    Btw, I can access the server control of master page from base page class via
    Cast + FinndControl,
    however this method doesn't work on access a user control. how to solve?

    Thanks in advance!
     
    RedHair, Mar 22, 2006
    #1
    1. Advertising

  2. RE: Access property and control of master page from a customized paren

    You could try exposing the control as a property in the master page.



    "RedHair" wrote:

    > I have a ASP.NET 2.0 web page which inherits a customized base page class
    > and have a master page,
    > their relation is as below
    >
    > Customized base page class --> web page --> master page
    >
    > How to access the property and control of master page from the customized
    > base page class?
    >
    > Btw, I can access the server control of master page from base page class via
    > Cast + FinndControl,
    > however this method doesn't work on access a user control. how to solve?
    >
    > Thanks in advance!
    >
    >
    >
     
    =?Utf-8?B?Y2xpY2tvbg==?=, Mar 22, 2006
    #2
    1. Advertising

  3. RedHair

    RedHair Guest

    Re: Access property and control of master page from a customized paren

    Thanks for reply, however the base class can't access the property of master
    page


    "clickon" <> wrote in message
    news:...
    > You could try exposing the control as a property in the master page.
    >
    >
    >
    > "RedHair" wrote:
    >
    >> I have a ASP.NET 2.0 web page which inherits a customized base page class
    >> and have a master page,
    >> their relation is as below
    >>
    >> Customized base page class --> web page --> master page
    >>
    >> How to access the property and control of master page from the customized
    >> base page class?
    >>
    >> Btw, I can access the server control of master page from base page class
    >> via
    >> Cast + FinndControl,
    >> however this method doesn't work on access a user control. how to solve?
    >>
    >> Thanks in advance!
    >>
    >>
    >>
     
    RedHair, Mar 22, 2006
    #3
  4. RedHair

    Guest

    I don't know if I understood your question correctly but here goes.

    'Access base class' master page.
    Dim myBMP As MasterPage = Me.MyBase.Master

    'Find a user control called "myControl" in base class' master
    Dim myControl As UserControl = myBMP.FindControl("myControl")
    'Or perhaps
    Dim myControl As UserControl = CType(MyBMP.FindControl("myControl"),
    UserControl)
     
    , Mar 22, 2006
    #4
  5. RedHair

    RedHair Guest

    I am trying to access the page's master page from this page's parent class.


    <>
    ???????:...
    >I don't know if I understood your question correctly but here goes.
    >
    > 'Access base class' master page.
    > Dim myBMP As MasterPage = Me.MyBase.Master
    >
    > 'Find a user control called "myControl" in base class' master
    > Dim myControl As UserControl = myBMP.FindControl("myControl")
    > 'Or perhaps
    > Dim myControl As UserControl = CType(MyBMP.FindControl("myControl"),
    > UserControl)
    >
     
    RedHair, Mar 23, 2006
    #5
  6. RedHair

    Guest

    Accessing the subclass from the base class violates the general OO
    principle that the base class should not know the subclass. It makes
    the base class dependent on its subclasses.

    Having said that, you can pass a reference of the subclass' masterpage
    to the base class. I have not tested the following code snippet.
    'In base class. Declare a variable to hold a reference to subclass'
    masterpage
    Protected ChildMaster As MasterPage

    'In subclass. Pass the reference to masterpage to base class
    Me.MyBase.ChildMaster = Me.Master

    Back in the base class you can access subclass' masterpage through
    ChildMaster.

    However, I would urge you to rethink your design.

    Regards.

    RedHair wrote:
    > I am trying to access the page's master page from this page's parent class.
    >
    >
    > <>
    > ???????:...
    > >I don't know if I understood your question correctly but here goes.
    > >
    > > 'Access base class' master page.
    > > Dim myBMP As MasterPage = Me.MyBase.Master
    > >
    > > 'Find a user control called "myControl" in base class' master
    > > Dim myControl As UserControl = myBMP.FindControl("myControl")
    > > 'Or perhaps
    > > Dim myControl As UserControl = CType(MyBMP.FindControl("myControl"),
    > > UserControl)
    > >
     
    , Mar 23, 2006
    #6
    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:
    1,133
    William Brogden
    Aug 5, 2004
  2. =?Utf-8?B?SmF5IFBvbmR5?=
    Replies:
    6
    Views:
    505
    =?Utf-8?B?SmF5IFBvbmR5?=
    Nov 14, 2007
  3. Nathan Sokalski
    Replies:
    25
    Views:
    1,495
    Nathan Sokalski
    Mar 4, 2010
  4. SerpentKiss2010
    Replies:
    0
    Views:
    2,545
    SerpentKiss2010
    Apr 6, 2011
  5. RedHair
    Replies:
    5
    Views:
    321
Loading...

Share This Page