Differences between codebehind and SRC

Source: Internet
Author: User
Use in ASP. NETCodeThe hidden method is used to design a web form, which 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: <% @ page Language = "C #" codebehind = "webform1.aspx. CS "autoeventwireup =" false "inherits =" webapplication1.webform1 "%> three attributes (inherits, SRC, and codebehind) are very confusing. The inheritsinherits attribute is used to define the code hiding 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
 
The <SCRIPT runat = "server"> </SCRIPT> label does not need to be used. The srcsrc attribute is used to specify the location of the "Code (hidden) file" in the file system, so that ASP. NET Framework can use just-in-time (JIT)
 
The compiler can find it when dynamically compiling a web form. The class specified with inherits is placed in this class code (hidden) file.
 
When ASP. NET Framework uses these classesProgramCentralized search,
 
If no code file is found, the code file provided in the src attribute will be re-compiled. Therefore, the src attribute and the inherits attribute are not mutually exclusive. Note that Visual Studio. NET does not use the src attribute,
This means that Visual Studio. NET always expects you to use the generate operation in the "generate" menu to generate the compiled assembly.
 
(It is usually compiled into a DLL and put it in the/bin directory. In this way, you can release the application system without publishing it.Source code),
 
In the future, dynamic compilation is not required. So if you are developing in Visual Studio. net ide,
 
Always pay attention to the use of the "regenerate" function to compile the changed classes. Otherwise, a series of problems such as the inability to find the classes will occur. Codebehind: 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.
 
Therefore, when using Visual Studio. net for development, you cannot rashly change the codebehind attribute to the src attribute. Their functions are different.

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.