Calling MasterPage Subroutines from a ContentPage

Discussion in 'ASP .Net' started by jeffmagill@gmail.com, Jun 20, 2006.

  1. Guest

    Is it possible? I haven't been able to find any information about this.
    Not on the web, not in books.

    Is it possible to call a function or subroutine which is defined in a
    MasterPage from it's derivative ContentPage?

    Thanks.
    Jeff
    , Jun 20, 2006
    #1
    1. Advertising

  2. In your aspx add:
    <%@ MasterType virtualPath="~/<MasterPageName>.master"%>

    Then in its codebehind:
    this.Master.MyMethod()

    Hope this is what you needed.

    "" wrote:

    > Is it possible? I haven't been able to find any information about this.
    > Not on the web, not in books.
    >
    > Is it possible to call a function or subroutine which is defined in a
    > MasterPage from it's derivative ContentPage?
    >
    > Thanks.
    > Jeff
    >
    >
    =?Utf-8?B?TWFya0F1cml0?=, Jun 20, 2006
    #2
    1. Advertising

  3. Hi Mark,

    Thanks for pointing this out. K. Scott Allen has a more detailed, but
    in VB.NET, article here:

    http://odetocode.com/Blogs/scott/archive/2005/07/16/1944.aspx

    Tod Birdsall, MCSD for .NET
    software blog: http://tod1d.net


    MarkAurit wrote:
    > In your aspx add:
    > <%@ MasterType virtualPath="~/<MasterPageName>.master"%>
    >
    > Then in its codebehind:
    > this.Master.MyMethod()
    >
    > Hope this is what you needed.
    >
    > "" wrote:
    >
    > > Is it possible? I haven't been able to find any information about this.
    > > Not on the web, not in books.
    > >
    > > Is it possible to call a function or subroutine which is defined in a
    > > MasterPage from it's derivative ContentPage?
    > >
    > > Thanks.
    > > Jeff
    > >
    > >
    Tod Birdsall, MCSD for .NET, Jun 20, 2006
    #3
  4. Guest

    Thanks for your quick responses!! I'll let you guys know how it turns
    out.

    You're welcome for point this out. If you want, I can point out more
    problems sooner :)

    Jeff

    Tod Birdsall, MCSD for .NET wrote:
    > Hi Mark,
    >
    > Thanks for pointing this out. K. Scott Allen has a more detailed, but
    > in VB.NET, article here:
    >
    > http://odetocode.com/Blogs/scott/archive/2005/07/16/1944.aspx
    >
    > Tod Birdsall, MCSD for .NET
    > software blog: http://tod1d.net
    >
    >
    > MarkAurit wrote:
    > > In your aspx add:
    > > <%@ MasterType virtualPath="~/<MasterPageName>.master"%>
    > >
    > > Then in its codebehind:
    > > this.Master.MyMethod()
    > >
    > > Hope this is what you needed.
    > >
    > > "" wrote:
    > >
    > > > Is it possible? I haven't been able to find any information about this.
    > > > Not on the web, not in books.
    > > >
    > > > Is it possible to call a function or subroutine which is defined in a
    > > > MasterPage from it's derivative ContentPage?
    > > >
    > > > Thanks.
    > > > Jeff
    > > >
    > > >
    , Jun 20, 2006
    #4
  5. clintonG Guest

    You'll be back ;-)

    <%= Clinton Gallagher
    NET csgallagher AT metromilwaukee.com
    URL http://www.metromilwaukee.com/clintongallagher/

    <> wrote in message
    news:...
    > Thanks for your quick responses!! I'll let you guys know how it turns
    > out.
    >
    > You're welcome for point this out. If you want, I can point out more
    > problems sooner :)
    >
    > Jeff
    >
    > Tod Birdsall, MCSD for .NET wrote:
    >> Hi Mark,
    >>
    >> Thanks for pointing this out. K. Scott Allen has a more detailed, but
    >> in VB.NET, article here:
    >>
    >> http://odetocode.com/Blogs/scott/archive/2005/07/16/1944.aspx
    >>
    >> Tod Birdsall, MCSD for .NET
    >> software blog: http://tod1d.net
    >>
    >>
    >> MarkAurit wrote:
    >> > In your aspx add:
    >> > <%@ MasterType virtualPath="~/<MasterPageName>.master"%>
    >> >
    >> > Then in its codebehind:
    >> > this.Master.MyMethod()
    >> >
    >> > Hope this is what you needed.
    >> >
    >> > "" wrote:
    >> >
    >> > > Is it possible? I haven't been able to find any information about
    >> > > this.
    >> > > Not on the web, not in books.
    >> > >
    >> > > Is it possible to call a function or subroutine which is defined in a
    >> > > MasterPage from it's derivative ContentPage?
    >> > >
    >> > > Thanks.
    >> > > Jeff
    >> > >
    >> > >

    >
    clintonG, Jun 21, 2006
    #5
  6. Guest

    It worked prefectly. Thank you so much guys!
    , Jun 21, 2006
    #6
  7. TuckWong

    Joined:
    Jan 11, 2013
    Messages:
    2
    I HOPE MY SOLUTION HELPS MANY SEEKING ANSWERS LIKE MYSELF BUT FAILED.
    (1) One thing you guys left out in contentpage calling masterpage.
    In ContentPage aspx, you cannot add this
    <%
    @ MasterType virtualpath="~/{Your Masterpage}.Master" %>
    When compile, you get compiler error
    So, dont add!
    (2) Calling a Public Routine (Property or Function) that is in Masterpage
    In Content Page:
    just write code as
    CType
    (Master, {Your MasterPage Name}).{Your MasterPage.PublicRoutine)

    That's all. However, do note that inside masterpage page_load,what you declared here will return empty in your calling.

    TuckWong, Jan 11, 2013
    #7
  8. TuckWong

    Joined:
    Jan 11, 2013
    Messages:
    2
    IN ADDITION TO MY COMMENTS:
    (1)When contentpage is called, masterpage will load next. So....
    In ContentPage Page_load, When you reference a masterpage routine, you may get empty result because the Masterpage.pageload is loaded second.
    Hence, whatever variables you assigned value is not captured yet.

    Again, just write as:
    Dim a as string
    a = CType(Master, {Your MasterPage Name}).{Your MasterPage.PublicRoutine)

    Hope I helped someone.

    Cheers,
    Tuck
    june1629 at yahoo dot come
    TuckWong, Jan 11, 2013
    #8
    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. Replies:
    1
    Views:
    489
    Scott Allen
    Nov 22, 2005
  2. User
    Replies:
    9
    Views:
    10,423
  3. dawg1998
    Replies:
    2
    Views:
    3,605
    zehramb
    May 31, 2010
  4. =?Utf-8?B?ZGF3ZzE5OTg=?=
    Replies:
    0
    Views:
    472
    =?Utf-8?B?ZGF3ZzE5OTg=?=
    Mar 15, 2006
  5. Elmo Watson
    Replies:
    1
    Views:
    584
    Eliyahu Goldin
    May 8, 2007
Loading...

Share This Page