Access Master Page Method in asp.net c#

From you Content page you can use this to achieve the requirement and make sure it marked as a public not protected:

VB

TryCast(Me.Master, MyMasterPage).UpdateCart()

C#

(this.Master as MyMasterPage).UpdateCart();

Do it like this:

SiteMaster master = new SiteMaster();
//now call the master page method
master.test()

Example

//master page code behind
public partial class SiteMaster : System.Web.UI.MasterPage
{

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    //test method
    public void test()
    {
    }

}

//content page code behind
public partial class About : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        SiteMaster master = new SiteMaster();
        master.test();
    }

}

Or make the SiteMaster method static and just call it directly:

SiteMaster.MyStaticMethod()

Tags:

C#

Vb.Net

Asp.Net