views:

41

answers:

3

I am trying to reference a variable within my MasterPage but I am receiving errors.

I have tried

<%@ MasterType" %>

which gives the following error:

Compiler Error Message: CS0030: Cannot convert type 'IPAMIntranet.IPAMIntranetMaster' to 'ASP.ipamintranetmaster_master'

and

string tVar = ((MyNamespace.MyMasterPage)Master).variable 

which gives the following error:

Unable to cast object of type 'ASP.ipamintranetmaster_master' to type 'IPAMIntranet.IPAMIntranetMaster'.

Does anyone know what is happening or am I missing something.

A: 

You need to specify the virtual path to the Masterpage in the content page.

<%@ MasterType VirtualPath="Master.Master" %>
Germ
I did try <%@ MasterType VirtualPath="~/IPAMIntranetMaster.Master" %>and I am getting that error.
mattgcon
A: 

From the looks of it, it seems that your master page either isn't the type IPAMIntranet.IPAMIntranetMaster, or doesn't inherit from IPAMIntranet.IPAMIntranetMaster, the only way to resolve this would be to make it inherit, or make sure the type is correct.

The MasterType directive can take the whatever class the Master is castable to, it's mainly for intellisense. You can provide either the VirtualPath to the Master or TypeName, which can be the Master's class, a base class, or an interface, whichever is more appropriate for your situation.

Nick Craver
This is the first line in the HTML code for the MasterPage:<%@ Master Language="C#" AutoEventWireup="true" CodeFile="IPAMIntranetMaster.Master.cs" CodeBehind="IPAMIntranetMaster.Master.cs" Inherits="IPAMIntranet.IPAMIntranetMaster" %>
mattgcon
@mattgcon - What does your `@Page` directive look like for this page?
Nick Craver
This is my content page directive:<%@ Page Language="C#" MasterPageFile="~/IPAMIntranetMaster.Master" AutoEventWireup="true" CodeBehind="IPAMPeople_HomePage.aspx.cs" Inherits="IPAMIntranet.IPAM_People.IPAMPeople_HomePage" %>
mattgcon
A: 

I worked this out by using an interface instead.

mattgcon