asp.net - 页面指​​令继承属性

标签 asp.net webforms

我只是想知道是否有人知道 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属性告诉您包含与页面关联的类的编译文件的名称。

假设 Default.aspx.cs 如下所示:-

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

   public class Employee
   {
      //
   }
}

自从在Default.aspx.cs文件中可以有多个类(默认和员工),在本例中为 Inherits属性指定继承哪个类。

关于asp.net - 页面指​​令继承属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33295718/

相关文章:

asp.net - 静态容器已经有一个与之关联的内核

asp.net - Telerik RadEditor HTTP POST VALUE 未更新(ASP.NET Web 表单)

c# - 如何找到文本框文本的最后一个字符?

c# - 如何检查本地主机

asp.net - 提供旧文件的 Azure Web 应用程序

C# (ASP.Net) 将选择值链接到代码隐藏中的常量

asp.net - 我可以在 ASP.NET WEB FORMS 中使用 Entity Framework 的验证功能吗

c# - 如何使用 iTextSharp 填充单选按钮

c# - 有没有一种方法可以在没有例如的情况下对单个项目进行数据绑定(bind)。中继器控件?

c# - 更改正在验证的控件的边框或背景颜色?