C# 为我的asp.net页面添加自定义基类会产生错误
我尝试使用自定义派生页面,而不是System.Web.UI.page作为网页的基类,但是Visual Studio 2012(ASP.Net)拒绝识别新的基类。代码看起来不错,只是VS不识别新的基类C# 为我的asp.net页面添加自定义基类会产生错误,c#,asp.net,C#,Asp.net,我尝试使用自定义派生页面,而不是System.Web.UI.page作为网页的基类,但是Visual Studio 2012(ASP.Net)拒绝识别新的基类。代码看起来不错,只是VS不识别新的基类 我在项目根目录下创建了一个名为App_Code的文件夹 在该文件夹中,我添加了一个名为SitePage.cs的新ASP.net类 进入SitePage.cs,以下是内容 using System; using System.Collections.Generic; using System.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
public class SitePage : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
}
public SitePage()
{
}
}想法?在默认设置之前,您必须将其作为参考(在解决方案资源管理器中查找“参考”选项)。aspx.cs将知道它是什么 在创建自定义基类之后,但在从页面更改基类之前,您需要构建项目 所以,现在你要做的是:
- 确保
继承自Default
System.Web.UI.Page
- 构建您的项目
- 重新应用
作为SitePage
Default
public partial class Default : SitePage