【发布时间】:2015-12-10 03:04:04
【问题描述】:
我一直在尝试链接 Web 表单,以便能够访问母版页中的变量。我在它起作用之前就这样做了。但是现在当我这样做时,我得到了一个错误。
Site.Master 中的代码
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
Site.Master.cs 中的代码
public partial class Site : System.Web.UI.MasterPage
{
public string hi = "";
protected void Page_Load(object sender, EventArgs e)
{
}
}
WebForm1.aspx中的代码:
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %>
<%@ MasterType VirtualPath="~/Site.master" %>
WebForm1.aspx.cs 中的代码
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Master.hi="new"
}
}
当我将鼠标悬停在 hi 上时,我会收到此消息
Error in Visual Studio - "You can use navigation bar to switch contexts
这是另一张图片 Screenshot
如果你们能帮助我,那就太好了
【问题讨论】:
-
@Sachu,我刚刚添加了图片。
-
你缺少分号
Master.hi="new"; -
@Sachu 当我将鼠标悬停在“hi”上时出现错误可以找到“hi”的定义,并且没有扩展方法“hi”接受“MasterPage”类型的第一个参数(您是否缺少 using 指令或程序集引用?) Devry - 高级 Web 开发项目 Z:\Developer\Visual Studio 2015\Projects\Devry - 高级 Web 开发项目\Devry - 高级 Web 开发项目\WebForm1.aspx.cs 12'
-
希望这个链接对你有帮助 [link]dotnetfunda.com/articles/show/1507/…
-
嗨@MosesAronov,您找到解决此问题的方法了吗?我现在在一个 asp.net MVC 项目中遇到了同样的问题。
标签: c# asp.net visual-studio