Top 10 skills in ASP. NET Programming (2)

Source: Internet
Author: User
Tags net command net command line

This article continues with 10 tips that programmers need to pay attention to when programming ASP. NET.

6. Differences between HyperLink controls and LinkButton controls

For Web visitors, the HyperLink and LinkButton controls are the same, but they still have major functional differences.

When a user clicks the control, the HyperLink control will immediately "navigate" the user to the target URL, and the table pieces will not be sent back to the server. The LinkButton control first sends the table to the server, and then navigating the user to the target URL. If server-side processing is required before the target URL is reached, use the LinkButton control. If server-side processing is not required, you can use the HyperLink control.

7. Comment on the code

This technique is not intended for asp.net programming, but it is a good programming habit.

Annotations should not only describe what operations the code performs, but also indicate the reason. For example, not just in comments, it indicates that the traversal array is to calculate a value based on an algorithm, unless the algorithm is quite simple, otherwise, the algorithm should be briefly described.

Different programming languages in the. net project have different annotations. The following is a brief description:

 
 
  1. HTML <! -- Comment -->
  2.  
  3. JavaScript// Comment 
  4.  
  5. Vbscript' comment
  6.  
  7. Vb.net' comment
  8.  
  9. C #// Comment 
  10.  
  11. /* Multiline content 
  12.  
  13. Annotations 
  14.  
  15. */ 
  16.  
  17. SQL -- Comment
  18.  

There is no annotator In the start and end tags of the server control, but the server can ignore all attributes that it cannot recognize. Therefore, we can insert comments by using unspecified attributes. The following is an example:

 
 
  1. <Asp: TextBox
  2.  
  3. Id ="TxtLastName" 
  4.  
  5. Size ="40" 
  6.  
  7. Comment ="This is my comment" 
  8.  
  9. Runat ="Server"/>
  10.  

It is very easy to annotate the source code in Visual Studio. net. The lines to be annotated are displayed in High Brightness. Press Ctrl + K + C to add comments. To delete a comment, you only need to display the commented code with High Brightness and press Ctrl + K + U.

In the C # project, we can also use the // input XML comment section at the beginning of each line. In the annotations section, we can use the following XML tag to organize Annotations:

 
 
  1. <summary></summary>  
  2.  
  3. <remarks></remarks >  
  4.  
  5. <param></param>  
  6.  
  7. <returns></returns>  
  8.  
  9. <newpara></newpara>  
  10.  

To view the formatted reports of these XML annotations in Visual Studio. net, select the "Tools" menu item and then select the "Create annotation Web page" menu item.

8. Use the trace method and trace properties to record the execution of webpages in the Page Directory.

An old technique of debugging a program is to insert an output statement into the key points of a program. Normally, the output information contains the values of important variables, relevant information can be output to the screen, log file, or database.

In asp.net, this debugging technology is easier to use by using the trace attribute in the Page command. The Page command is a line of code at the beginning of the ASPX file, which provides the compiler instructions. The Page command contains one or more attributes to provide the compiler with information such as the programming language used, the location of the Code support file, or the name of the class to be inherited.

One of the attributes in the Page command is trace, whose values may be true or false. Below is a typical Page command, where the trace attribute value is true:

 
 
  1. <%@ Page language="c#" trace="true" %> 

If the trace attribute value is set to true, the web page generated by the ASPX file is displayed. In addition to the webpage, a large amount of other information about the page is displayed. The information is displayed in the following table:

· The Request details provide the Session ID, Request time, and Request status code.

· Trace Information contains a list of Trace logs and web page lifecycle steps in chronological order. You can also add custom information to it.

· The Control tree lists all controls on a webpage in a hierarchical manner, including the size of each control in bytes.

· The Cookies set lists all Cookies created on this webpage.

· Header set HTTP headers and their values.

· Server variables are Server environment variables related to the webpage.

Trace logs contained in the Trace Information section are the most useful. Here we can insert our own Trace commands. There are two methods in the trace class to insert the command in the Trace log: trace. write and Trace. warn, except Trace. the Warn command displays and traces in red. the Write command is displayed in a black font, and they are the same. Below is a screen snapshot of the tracking log, which contains several Trace. Warn commands.

The most convenient feature in tracking logs is that we can insert Trace into the entire code during development and testing. write and Trace. warn statements. When the application is finally delivered, you can change the trace attribute value in the Page command to disable these commands from working, instead of deleting these output statements before deploying the application.

9. Use stored procedures

Microsoft's SQL Server and other modern relational databases use SQL commands to define and process queries. An SQL statement or a series of SQL statements are submitted to SQL Server. SQL Server parses the command, creates a query plan, optimizes it, and executes the query plan, this takes a lot of time.

Stored procedures are a series of SQL commands pre-parsed and optimized by the query processor. These commands are stored and can be executed quickly. A stored procedure is also called sprocs. It can receive input parameters so that a single stored procedure can process a large range of specific queries.

Because sprocs is pre-parsed, it is more important for complex queries, and its query plan is pre-optimized. Therefore, calling the query process is much faster than executing SQL statements with the same function.

10. Use the. net command line

The. net command line tool runs in the Command Prompt window. To make the command executable, it must reside in the current directory of the command prompt, or by setting the PATH environment variable.

. Net SDK installs a menu item on the "Start" menu, which can open a command prompt window that correctly sets the PATH environment variable. You can choose Start> program> Microsoft Visual Studio. net "->" Visual Studio.. net tool> Visual Studio.. net command prompt.

By dragging this menu item from the menu to the desktop and pressing Ctrl + C, you can copy the shortcut of this menu item to the desktop, which is very convenient to use.

The 10 skills that need to be paid attention to in asp.net programming are described. I hope they will be helpful to you.

  1. Introduction to ASP. net mvc Framework
  2. Introduction to MvcAjaxPanel in ASP. NET MVC
  3. ASP. net mvc Framework to save UpdatePanel
  4. Use ASP. net mvc source code to find a solution
  5. ActionInvoker of ASP. net mvc Framework

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.