In this document, we will discuss 10 techniques that programmers need to pay attention to using ASP.NET development applications. These techniques involve the use of default controls, form names to the StringBuilder class, help programmers Can adapt to the .NET environment as soon as possible.
1. When using Visual Studio .NET, do not use the default name except for direct or non-reference objects.
One of the benefits of .NET is that all source code and configuration files are plain text files that can be edited using any text editor such as NotePad or WordPad. If you don't want, we don't have to use Visual Studio .NET as an integrated development environment. But use Visual Studio .NET, we can see the file in the Windows File Manager, or browse the file from the text editor outside of the text editor outside the Visual Studio .NET.
It has many benefits as the integrated development environment using Visual Studio .NET, the most prominent benefits are greatly improved production efficiency. Using Visual Studio. NET, we can develop software faster in the case of paying smaller costs. As an integrated development environment, an IntelliSense is provided with automatic code completion, providing dynamic help, real-time prompts for syntax errors when entering methods or functions, and other functions that can improve production efficiency.
Like other complex tools, Visual Studio .NET will also make us a frustration in front of how to give up its role and master their "habits". Sometimes it is like a black box that is difficult to understand, generate a lot of files and many useless code.
A feature of Visual Studio .NET is, whether objects in classes, controls, or forms can provide a default name for new objects. For example, if we created a new ASP.NET Web Application, its default name will be WebApplication1. We can easily change the name of the application in the New Engineering dialog, but at the same time, it is only the name of the name space of the application and its virtual directory, the default name of the source code file is still Webform1.aspx. And WebForm1.aspx.cs (C # Project) or WebForm1.aspx.vb (VB.NET Project).
We can change the file names used by the ASPX and code in the scenario browser, but the name of the web page will still be WebForm1. If a button is generated on the web form, its default name will be button1. In fact, the names of all controls are constructed by the type and number of controls.
We can, should also modify all the forms and controls of the application into meaningful names. For smaller demo programs, the default name can also be competent, but if the application has many buttons and labels by multiple forms, each form, like frmstartup, frmdataentry, and fmreports The names such as Form1, Form2 and Form3 are easier to understand and maintain.
If the control on the form is referenced elsewhere in the code, it is more important to have a meaningful name. BTNOK, BTNCANCANCEL and BTNPRINT have made the people who look at the code easier to understand, and thus, more easily than the names of Button1, Button2, button3 more easily.
A good way to modify a name that appears in all files in an engineering is that in order in the Visual Studio .Net menu, select the Edit -> Discovery and Replace "->" Replace "command. When you read the code written in two weeks, we often like these code for the first time, so there is a need to help us understand the name of its meaning.
2, even if you do not use Visual Studio .NET, use code support files to improve applications' performance in all ASP.NET Web projects such as web applications, web services, or web controls, Visual Studio .NET The code supports files. The code support file makes the project better organization, module, and more suitable for multiplayer development teams. In addition, it also brings improvement in performance.
The content of the code support file is compiled into a class in a combined file, typically a DLL file, sometimes it can be an Exe file. This file resides in the application's assembly cache, you can get it immediately when the application starts. If the code is included in the tag or in the ASPX file code, it will still be compiled into a web page class. In this case, whenever the web page is loaded in the application conversation, it is necessary to re-compile, and the compiled class will reside in memory. Whenever the computer starts, IIS stop, restart, or source code, the file must be recompiled when the configuration file changes. Although not large, the performance loss caused by this is also considerable.
3, try to reduce the form and send
Whenever you click on the Button, LinkButton or ImageButton control on the web page, the form will be sent to the server. If the autopostback property of the control is set to True, if the status of CHECKBOX, CheckBoxList is changed, the form will send the form to the server.
Each time the form is sent back to the server, it will be reloaded, starting the Page_Load event, performs all the code in the Page_Load event handler. Playing the initialization code of the web page is the most appropriate. We often want to execute some code at each load, and hope that only other code is performed when the web page is first loaded, and even some code will execute each time the first load is loaded.
This feature can be accomplished using the ISPostBack feature. The value of this property is False when the web page is loaded. If the web page is reloaded due to the return, the value of the iSPostBack property is set to TRUE. By testing, the specified code can be performed at any time. Here is the associated C # code:
Protected void Page_load (Object sender, eventargs e) {// page each load, some operation if (! ispostback) {// page first loads} ELSE {// The operation performed when returning }
// Operations performed when loading each time}
We hope that try not to cause a return (each time the return will require a series of operations), even after the return is caused. It is also hoped that you can perform as little as possible. Large-scale, waste time (such as database lookup) should especially avoid because they can extend the response time of the application.
4, use the StringBuilder class
The string is not variable in the .NET framework, which means changing the operator and method of the string return to the change of the string, which means that performance has improved space. When making a large number of string operations, using the StringBuilder class is a better choice.
The following C # code test uses two ways to generate the time required to generate a string from 10,000 subtrings. For the first time, a simple string series operation is used; the StringBuilder class is used for the second time. To view the result string, you can remove the following code to refer the annotation symbol:
<% @ Page language = "c #"%>