tags:

views:

142

answers:

2

I know we've done this before in another .aspx page that's using this master page. So I tried this in a new .aspx but for some reason, it is not recognizing the Master object. And the .aspx definitely is set to the master page in the page directive correctly and there's no errors to that effect:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class LandingPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Master.HideNavbar();
    }
}
+3  A: 

Try to reference your masterpage at your aspx file :

<%@ MasterType virtualpath="~/YourMasterPage.master" %>
Canavar
+1  A: 

to get typed Master page class in your code you need to define what type is it, either in Page directive or with MasterType directive on page:

<%@ Page  masterPageFile="~/MasterPage.master"%>

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

If you don't have these directives, you can always cast Master property in code:

(MasterPage)this.Master

see also here http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx

Edit:
is HideNavbar() method public?

Andrija