Plunging into .NET Development

Weblog Pieter Gheysens
Microsoft .NET Development - C# - Enterprise Library - Visual Studio 2005 Team System - Compuware DevPartner - ...
 


Friday, August 18

Access to master pages

In ASP.NET 2.0 it's possible to create a strongly typed reference to the master page by creating a @ MasterType directive ...

In my master page for example I have a HeaderTable at the top of the page, a ContentPlaceHolder for the body in the middle of the page and a FooterTable at the bottom of the page. Now, I want to hide the FooterTable in a web page that also uses the master page. How to do this programmatically ...

In the master page I've created a public property for the FooterTable.

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

{

    public HtmlTable FooterTable

    {

        get

        {

            return this.tableFooter;

        }

        set

        {

            this.tableFooter = value;

        }

    }

 

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

}


Secondly I've added the @ MasterType directive to the aspx-page after the usual @ Page directive.

<%@ MasterType VirtualPath="~/MasterPage.master" %>


Adding this directive lets you point (strong typing) directly to the public properties of the master page and that's how I've hidden the FooterTable in the Page_Load event.

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        this.Master.FooterTable.Visible = false;

    }

}

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home