Call a master page Method() from content page using c#

In the Master page code behind file define the method you want to call as Public.

public partial class MasterPage : System.Web.UI.MasterPage
{

public void ShowLicenseErrorImage()
{
this.IMG_LicenseExceedWarn.Visible =
this.lblLicenseMisuse.Visible =
this.lblDetails.Visible = true;
}

public void HideLicenseErrorImage()
{
this.IMG_LicenseExceedWarn.Visible =
this.lblLicenseMisuse.Visible =
this.lblDetails.Visible = false;
}

}

Now in the content page code befind type the following.

MasterPage master = (MasterPage)this.Master;
master.ShowLicenseErrorImage();

Where “MasterPage” is the class name of class in master page.

Thats it!!! :-)

One Response to “Call a master page Method() from content page using c#”

  1. KIRAN Says:

    Good one.

    It works !!!!!!

Leave a Reply