attribute inherits, SRC, codebehind differences of @page directives in "Goto" ASP

Source: Internet
Author: User

Inherits, SRC, codebehind

Designing Web Forms using the code-behind approach in ASP. Enables page code to be more clearly detached from HTML content into completely separate files.

Usually a @page directive is as follows:

<%@ page language= "C #" codebehind= "WebForm1.aspx.cs" inherits= "Webapplication1.webform1"%>

There are three attributes (Inherits, SRC, codebehind) that are very easy to confuse and are explained below separately.

Inherits

The Inherits property is used to define the code-behind class that the current Web form inherits from (the class is a derived class of System.Web.UI.Page).
This inherits property is only intended for Web forms written in code-behind, i.e., if your code is all in the Web form's <script runat= "server" ></script> tags, you don't have to use this property.

Src

The SRC attribute is used to specify the location of the code (hidden) file in the file system so that it can be found when the ASP. NET Framework uses the Just-in-time (JIT) compiler to dynamically compile Web forms. The class specified with Inherits is placed in this class code (hidden) file.
Typically, when the ASP. NET Framework uses these classes, it first looks in the compiled assembly,
If it is not found, the code file provided in the SRC attribute is recompiled, so the SRC attribute and the Inherits property are not mutually exclusive.

It is necessary to note that Visual Studio. NET does not use the SRC attribute, which means that Visual Studio. NET always expects you to use the build action in the Build menu to produce the compiled assembly (usually compiled into a DLL in the \ Bin directory, so that When you publish your application, you do not have to publish your source code, and you will not have to dynamically compile it in the future. So if you are developing in the Visual Studio. NET IDE, you should always be careful to use the regenerate function to compile the changed classes, otherwise there will be a series of problems such as what is not found in the class.

Codebehind

The Codebehind property is not a true ASP. Net property, it is not found in the ASP.
It's really just a Visual Studio. NET property, and Visual Studio. NET is borrowing this property to keep track of the Web Forms and the relative code-behind files in your project, such as when you put a server control on a Web form in your design environment, Vi Sual Studio. NET will automatically find the code-behind file that corresponds to the Web form and automatically insert the relevant code. Therefore, when developing with Visual Studio. NET, it is not easy to replace the Codebehind attribute with the SRC attribute, whose function is different.

attribute inherits, SRC, codebehind differences of @page directives in "Goto" ASP

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.