【发布时间】:2012-12-19 02:03:13
【问题描述】:
这个应该很简单。我正在制作一个非 MVC ASP.NET 2.0 站点。 VS2008 似乎生成带有<script> 区域的控件——我想要代码隐藏中的代码,所以我手动将其连接起来。
我有以下几点:
widget.ascx:
<%@ Control Language="C#" ClassName="widget" Codebehind="widget.ascx.cs" Inherits="widget"%>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
widget.ascx.cs:
namespace webapp
{
public partial class widget : System.Web.UI.Control
{
protected void Page_Load(object sender)
{
Label1.Text = Session["user_id"].ToString();
}
}
}
我从使用代码隐藏文件的 ASPX 页面复制并粘贴了这些内容,但是当我尝试编译时,我得到了 Label1 does not exist in this context 的错误。
感谢您对此事的所有帮助。
【问题讨论】:
标签: asp.net-2.0 code-behind ascx