Select ASP.net code writing policy

Source: Internet
Author: User
Tags visual studio
The Asp.net| strategy development community includes the contents of the. NET Framework, the most characteristic of which is asp.net web development. However, there is also a lot of discussion about legacy ASP code and its developers.



Many ASP developers are not really trained developers, they are often just HTML code writers, they are dealing with the ASP model is unreasonable. These developers often only know how to apply their ASP's general thinking to the asp.net environment, which they do not know to make the appropriate choice.



Shortcomings of the past
I particularly enjoy the stability of asp.net, especially when I am puzzled by the ASP development process. My confusion comes from the nature of the ASP, where all operations are concentrated in the same bucket, that is, an ASP page contains both source code and HTML. It is also similar to place Java script on a Web page, which is often referred to as inline (inline), but developers often refer to it as the Spaghetti Code (spaghetti Code).

In a development project, the combination of the plan and the development process does not match well with the project task, which typically occurs with Web user interface designers and program developers. Allowing Web developers to view ASP code tends to make developers feel uneasy and confusing to web developers. A more feasible approach is to separate the design process.



Separation and improvement
When mentioned. NET, Microsoft boasts object-oriented programming (OOP), and OOP features are more pronounced in asp.net. It allows source code to be detached from the Web markup through a code file (codebehind file) behind it. The Web markup is stored in an. aspx file, and the source code (vb.net,c#, and so on) resides in an accompanying code file. The codebehind file name depends on the development language used, but if we use vb.net to build a asp.net page called Testpage, the following file name is legal:

TestPage.aspx:Web Markup,java script and so on.
TestPage.aspx.vb: A file containing vb.net source code.


If you are using C #. NET language, codebehind files will be called TestPage.aspx.cs. The codebehind file contains a class that originates from a page class that is located in the System.UI.Web space name. The codebehind file is linked to the ASPX file with the @page flag and its accompanying file inherits attribute. The Inherits property points to the name of the Codebehind file and class, and this point does not require a file extension.

<%@ Page language= "C #" inherits= "Testpage"%>



The nature of the language represents the language of the page--not codebehind. Pages can use one language and another language used in codebehind files through inline (inline) code. The Inherits property specifies the base class (Codebehind Class) of the page.

By default, the Codebehind file uses the page class as its base class, but it can also use ordinary classes. This provides the possibility of building a master page of the program (master pages).



In Visual Studio. net method of processing
Using the codebehind file is visual Studio. The default attribute in the net development environment. For example, the @page flag that is established in the ASP.net page has the following syntax:

<%@ Page language= "C #" codebehind= "TestPage.aspx.cs"
Autoeventwireup= "false" inherits= "Testpage"%>



The above code contains two additional features:

The Codebehind property points to the codebehind file for the page. This property applies only to Visual Studio. NET.

The AutoEventWireup property indicates whether standard events are automatically connected to any handle in the code. Visual Studio. NET sets this property to False when handling event creation.



Visual Studio. NET compiles the codebehind file into an executable file that can be used in the Web program's Bin directory. This speeds up the loading of the page because the page is not compiled when it is first requested. On the other hand, the inline (inline) code is compiled once the first client is consulted.



Make your own choices.
OOP syntax is a support for separating the source code and user interface sections, but that does not mean that it works in all situations. The separation method relies on different factors (including development time and expertise), but having all the possible knowledge makes it easier to make decisions. Since the introduction of ASP.net, the topic of inline (inline) and behind code (CODEBEHIND) has been hotly debated.


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.