public abstract class PageBase : System.Web.UI.Page { ... }
当我注意到你也可以在ASP.NET视图中声明一个基页:
<%@ Page Language="C#" CodeFileBaseClass="PageBase.cs" CodeFile="page.aspx.cs" Inherits="page" %>
解决方法
例如,指定CodeFile =“page.aspx.cs”而不存在page.aspx.cs将导致:
Parser Error Message: The file '/page.aspx.cs' does not exist.
假设存在page.aspx.cs,则指定CodeFileBaseClass =“PageBase.cs”而不存在PageBase.cs将导致:
Parser Error Message: Could not load type 'PageBase.cs'.
另一方面,您可以从PageBase继承而不指定CodeFileBaseClass属性.但是,当从基类引用页面上的控件时,这可能会导致意外行为.
引用Microsoft’s @Page MSDN Documentation:
CodeFileBaseClass
Specifies the type name of a base class for a page and its associated code-behind class. This attribute is optional,but when it is used the
CodeFile attribute must also be present. Use this attribute when you want to implement a shared scenario,where you define common
fields (and optionally,associated events) in a base class to
reference the controls declared in a Web page. Because of the ASP.NET
code generation model,if you defined the fields in a base class
without using this attribute,at compile time new member deFinitions
would be generated for the controls declared in the Web page (within a
separate partial class stub),and your desired scenario would not
work. But if you use the CodeFileBaseClass attribute to associate
the base class with the page,and you make your partial class (its
name is assigned to the Inherits attribute and its source file is
referenced by the CodeFile attribute) inherit from the base class,then the fields in the base class will be able to reference the controls on the page after code generation.