Differences between Inherits, CodeFile, and CodeBehind in ASP. NET, codefilecodebehind

Source: Internet
Author: User

Differences between Inherits, CodeFile, and CodeBehind in ASP. NET, codefilecodebehind

Inherits, CodeFile, CodeBehind

Using the code hiding method in ASP. NET to design a Web form allows the Page code to be more clearly separated from the HTML content into a completely separate file.
Generally, a @ page command is as follows:
Copy codeThe Code is as follows: <% @ Page language = "c #" Codebehind = "WebForm1.aspx. cs" AutoEventWireup = "false"
Inherits = "WebApplication1.WebForm1" %>

The three attributes (Inherits, CodeFile, and CodeBehind) are very confusing.

Inherits (meaning of inheritance)

Msdn explanation: defines the code hidden classes for page inheritance. It can be any class derived from the Page class. This feature is used with the CodeFile feature, which contains the path to the source file of the Code hiding class. The Inherits feature uses C # As the page language time zone and is case-insensitive When Visual Basic is used as the page language.

If the Inherits feature does not contain a namespace, ASP. NET checks whether the ClassName feature contains a namespace. If so, ASP. NET tries to use the namespace of the ClassName feature to load the classes referenced in the Inherits feature. (This assumes that the Inherits and ClassName features use the same namespace .)

The Inherits attribute is used to define the code hidden class inherited by the current Web form (this class is the derived class of System. Web. UI. Page ).
This inherits attribute is only used for Web forms written in code hiding mode, that is, if your code is all in the Web form
Label, you do not need to use this attribute.

CodeFile

Msdn explanation: Specifies the path to the code hidden file referenced by the page. This feature is used with the Inherits feature to associate hidden source code files with webpages. This feature is only valid for compiled pages.

This feature is used for website projects.

Codebehind

Msdn explanation: specify the name of the compiled file that contains the class associated with the page. This feature cannot be used at runtime. This feature is used for Web application projects.

The Codebehind attribute is not a real ASP. NET attribute. It cannot be found in the ASP. NET document.
It is actually only a Visual Studio. NET attribute,
Visual Studio. NET uses this attribute to track and manage Web forms and hidden code files in a project,
For example, when you add a server control to a Web form in the design environment,
Visual Studio. NET automatically finds the hidden code file corresponding to the Web form and inserts the relevant code.


Codefile and inherits in ASPNET

Inherits is the inherited class, _ Default is the compiled class name, And App_Web_rwzx932t is the Assembly DLL;
Codefile is the name of the background code.

What is CodeFile in the source view of a page file in ASPNET? Inherits?

<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
Explanation:
1. Page Language = "C #" Page Language settings: C #.
2. AutoEventWireup = "true" Whether the page automatically triggers events: Page_Init events and Page_Load events.
3. CodeFile = "Default. aspx. cs" Page defines the script/code class name.
4. The script/code class defined on the Inherits = "_ Default" Page: __default.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.