ASP.net 通过内容页访问母版页变量
我有一个母版页:
<%@ Master Language="C#" AutoEventWireup="true" Codefile="AdminMaster.master.cs" Inherits="AlphaPackSite.MasterPages.AdminMaster" %>
然后我有一个公共变量:
public partial class AdminMaster : System.Web.UI.MasterPage
{
protected bool blnShowDialogue = false;
在我的内容页中我想设置此变量:
blnShowDialogue = true;
以便在我的母版页中我可以拥有代码:
$(function() {
<%if(blnShowDialogue == true){%>
$("#dialog").dialog();
<% } %>
}
这有意义吗?当我尝试 Master.blnShowDialogue 或 blnShowDialogue = 等的组合时,似乎没有任何效果。
名称“blnShowDialogue”不 存在于当前上下文中
I have a master page:
<%@ Master Language="C#" AutoEventWireup="true" Codefile="AdminMaster.master.cs" Inherits="AlphaPackSite.MasterPages.AdminMaster" %>
Then I have a public variable:
public partial class AdminMaster : System.Web.UI.MasterPage
{
protected bool blnShowDialogue = false;
In my content page I would like to set this variable:
blnShowDialogue = true;
So that in my master page I can have the code:
$(function() {
<%if(blnShowDialogue == true){%>
$("#dialog").dialog();
<% } %>
}
Does this make sense? When I try combinations of Master.blnShowDialogue, or blnShowDialogue = , etc etc nothing seems to work.
The name 'blnShowDialogue' does not
exist in the current context
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 @MasterType 指令,如下所述:
http://msdn.microsoft.com/ en-us/library/c8y19k6h.aspx
Use @MasterType directive, as explained here:
http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx
您需要将母版页转换为实际类型。
否则 Master 将仅引用基类 Master - 您正在尝试访问实际类中的属性,该属性派生自 <大师班。
您收到的错误是因为类 System.Web.UI.MasterPage 中不存在名为 blnShowDialogue 的属性 - 这是有道理的,因为您没有告诉它您尝试引用哪个特定 MasterPage 实例。
希望有帮助。
You need to cast the Master page to the actual type.
Otherwise Master will simply be referring to the base class Master - you're trying to access a property in your actual class which derives from the Master class.
The error you are getting is because a property called blnShowDialogue does not exist in the class System.Web.UI.MasterPage - which makes sense, as you're not telling it which specific MasterPage instance you are trying to refer to.
Hope that helps.