我在Visual Studio中创建了一个新的Web应用程序。但我无法访问从Masterpage内容到同一主页的代码隐藏的变量:
我有一个.master页面:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="Intra.Private.Site1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder> </head> <body>
<form id="form1" runat="server">
<div>
<%=Test %>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form> </body> </html>
.master.cs fil包含:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Intra.Private
{
public partial class Site1 : System.Web.UI.MasterPage
{
public string Test = "";
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
“&lt;%= Test%&gt;”方法不起作用:我收到错误“测试”在当前上下文中不存在 ...
我已经尝试声明protected string Test
而不是public string Test
,但这并不是更好......
你有什么想法吗?