Asp. NET in the Inherits, CodeFile, codebehind the difference between detailed _ practical skills

Source: Internet
Author: User
Tags inheritance

Inherits, CodeFile, codebehind

Using code-behind methods in asp.net to design Web Forms enables page code to be more clearly detached from HTML content to completely separate files.
Usually a @page instruction is as follows:

Copy Code code as follows:
<%@ Page language= "C #" codebehind= "WebForm1.aspx.cs" autoeventwireup= "false"
inherits= "Webapplication1.webform1"%>

There are three attributes (Inherits, CodeFile, codebehind) that are easily confusing, as described below.

Inherits (meaning of inheritance)

MSDN Explanation: Defines a code-behind class for page inheritance. It can be any class that derives from the Page class. This attribute is used with the CodeFile attribute, which contains the path to the source file of the code-behind class. The Inherits attribute is case-sensitive when using C # as a page language, and is case-insensitive when using Visual Basic as the page language.

If the Inherits attribute does not contain a namespace, asp.net checks whether the ClassName attribute contains a namespace. If it is included, ASP.net will attempt to load the class referenced in the Inherits attribute using the namespace of the ClassName attribute. (This assumes that the Inherits attribute and the ClassName attribute use the same namespace.) )

The Inherits property is used to define the code-behind class that the current Web form inherits (the class is a derived class of System.Web.UI.Page).
This inherits property is only used for Web forms written in code-behind, that is, if your code is all in the Web Form
Tag, you don't have to use this property.

CodeFile

MSDN Explanation: Specifies the path to the code-behind file that points to the page reference. This attribute is used with the Inherits attribute to associate a code-behind source file with a Web page. This attribute is valid only for compiled pages.

This attribute is used for Web site projects.

Codebehind

MSDN Explanation: Specifies the name of the compiled file that contains the class associated with the page. This attribute cannot be used at run time. This attribute is used for WEB application projects.

The Codebehind property is not a true ASP.net property and cannot be found in asp.net documents.
It's actually just a Visual Studio. NET attribute,
Visual Studio. NET borrows this property to keep track of the Web forms and the relative code-behind files in the management project.
For example, when you put a server control on a Web form in a design environment,
Visual Studio. NET automatically finds the code-behind file that corresponds to the Web form and automatically inserts the associated code.

Related Article

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.