Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
asp.net. NET Framework Version 2.0 come out for a long time, VS. Beta2 also have, in recent times has been playing on the intermittent asp.net, found that just learn soon things will have to update, do not update is really not.
It's a very useful feature to start with the separation of the code from the ASP.net, especially in team work, I think.
In the. NET Framework Version 1.0/1.1, Microsoft teaches us how to separate code from performance:
1, first of all, add the following line to the @page directive of the. aspx file:
<%@ Page language= "vb" autoeventwireup= "false" codebehind= "SamplePage.aspx.vb" inherits= " Sampleproject.samplepage "%>
* Note: The Codebehind attribute here can be changed to SRC attribute
2. When using a background code file, that is, a. vb file, you must declare an instance in the background code for each control used within the presentation file, as follows:
Protected WithEvents Lblmessage as Label
Forget it, but the browser will tell you "the name" Lblmessage is not declared!
According to the words on MSDN:
The Code-behind class is a complete class definition; It contains instance variables for all controls on the page, explicit event binding using delegates, and.
All the above is the past, talk about the present situation.
In the. NET Framework Version 2.0, Microsoft told us that it was too troublesome to implement code and performance separation before, bro, now we can do it like this:
1. The @page instruction in the. aspx file is still to be written, but it is changed to write this:
<%@ page language= "VB" compilewith= "SamplePage.aspx.vb" classname= "samplepage_aspx"%>
With the Compilewith attribute to replace the codebehind and SRC attributes, the more and more properties I think should be the necessary price for backwards compatibility, classname indicate the class used by the background file.
2. When using the background code file, you do not have to declare an instance for each control used in the presentation file, where Microsoft takes advantage of a new language feature known as partial classes.
The Code-behind file for a page was not a complete class definition. Instead, it includes only the application code for you need, such as event handlers. The code-behind partial class does not need to include instance variables or explicit event binding. asp.net can infer the control instances and derive an event bindings from the markup during.
This does reduce the code, in VS2005, Microsoft claimed to be able to reduce 70% of the code, I will learn here, I do not know if there are any other code reduction places.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.