页面指​​令继承 属性

Page directives inherits property

我只是想知道是否有人知道 Inherits 属性在这个 Page 指令中的含义以及它为什么使用 ._Default。

根据 MSDN:-

Defines a code-behind class for the page to inherit. This can be any class derived from the Page class. This attribute is used with the CodeFile attribute, which contains the path to the source file for the code-behind class.

假设您的页面 Default.aspx 具有以下页面指令:-

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" 
    Inherits="MyNamespace.Default" %>

CodeBehind 属性告诉您包含与页面关联的 class 的编译文件的名称。

假设 Default.aspx.cs 看起来像这样:-

namespace MyNamespace
{
   public partial class Default: System.Web.UI.Page
   {
       //
   }

   public class Employee
   {
      //
   }
}

由于在 Default.aspx.cs 文件中可以有多个 classes(默认和员工),在这种情况下,Inherits 属性指定要继承哪个 class。