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. Advertisements

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

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

    Hope this is what you needed.
     
    =?Utf-8?B?TWFya0F1cml0?=, Jun 20, 2006
    #2
    1. Advertisements

  3. 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
     
    , Jun 20, 2006
    #4
  5. clintonG Guest

    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
    Likes Received:
    0
    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
    Likes Received:
    0
    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. Advertisements

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 (here). After that, you can post your question and our members will help you out.