Call a method from MasterPage in Content Page

To access a method from master page in the content page ensure first:

  •       The method in master page is declared as public

than call this code from your content page code behind:

                     MasterPageClassName MyMasterPage = (MasterPageClassName)Page.Master;

         MyMasterPage.SetMenuToRegistered();

where:

  • SetMenuToRegistered() - is a method positioned in the master page class.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted @ Monday, December 01, 2008 2:58 AM

Comments on this entry:

Gravatar # re: Call a method from MasterPage in Content Page
by Diadiora Alexandru at 1/12/2009 10:51 PM

Thanks for your remark, I corrected the issue.
Gravatar # re: Call a method from MasterPage in Content Page
by Shaikh Faraz at 1/12/2010 4:59 AM

Hi,
I was spent my 2 hours on this but none of scripts work for me your code only worked for me thanks great code.
Gravatar # re: Call a method from MasterPage in Content Page
by Safwan Ahmed at 9/22/2010 2:16 AM

buddy really outstading code thanks buddy.
Gravatar # re: Call a method from MasterPage in Content Page
by Amol at 4/19/2011 11:10 PM

That's fine..
but let's consider scenario that,
I have
1. MainMaster.master page
2. ChildMaster.master which inherits MainMaster
3. ContentPage.aspx which inherits ChildMaster

Now I wanna call method defined in MainMaster page in the ContentPage

Is that possible?
and How?
Gravatar # re: Call a method from MasterPage in Content Page
by himasnhu at 11/15/2011 12:43 AM

Hey thanks a lot .
it works fine!!!
:)
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: