开发者

Accessing MasterPage variable in content page

开发者 https://www.devze.com 2022-12-27 13:05 出处:网络
I am trying to reference a variable within my MasterPage but I am receiving errors. I have tried <%@ MasterType\" %>

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 

wh开发者_StackOverflowich 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.


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

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


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.


I worked this out by using an interface instead.

0

精彩评论

暂无评论...
验证码 换一张
取 消