2010-04-21 91 views
0

我想在我的母版页中引用一个变量,但我收到错误。在内容页面访问MasterPage变量

我已经试过

<%@ MasterType" %> 

它提供了以下错误:

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

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

它提供了以下错误:

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

有人知道发生了什么,或者我错过了什么。

回答

0

我通过使用接口来解决这个问题。

0

您需要在内容页面中指定主页面的虚拟路径。

<%@ MasterType VirtualPath="Master.Master" %> 
+0

我尝试了 <%@ MasterType VirtualPath =“〜/ IPAMIntranetMaster.Master”%> 我发现了这个错误。 – mattgcon 2010-04-21 20:42:16

0

从外观上来看,似乎你的母版页或者不是类型IPAMIntranet.IPAMIntranetMaster,或不从IPAMIntranet.IPAMIntranetMaster继承,唯一的办法来解决,这将是使它继承,或使确定类型是正确的。

MasterType指令可以采用主人可以施放的任何等级,主要用于智能感知。您可以向Master提供VirtualPath或为Master提供TypeName,这可以是Master的类,基类或接口,以适合您的情况为准。

+0

这是MasterPage HTML代码中的第一行: <%@ Master Language =“C#”AutoEventWireup =“true”CodeFile =“IPAMIntranetMaster.Master.cs”CodeBehind =“IPAMIntranetMaster.Master.cs”Inherits =“ IPAMIntranet.IPAMIntranetMaster“%> – mattgcon 2010-04-21 20:43:31

+0

@mattgcon - 你的'@ Page'指令对于这个页面是什么样的? – 2010-04-21 20:46:47

+0

这是我的内容页指令: <%@页面语言= “C#” 的MasterPageFile = “〜/ IPAMIntranetMaster.Master” AutoEventWireup = “真” 代码隐藏= “IPAMPeople_HomePage.aspx.cs” 继承=“IPAMIntranet.IPAM_People.IPAMPeople_HomePage “%> – mattgcon 2010-04-21 21:16:04