ASP. NET comments and server comments

Source: Internet
Author: User

Server-side ASP. NET comment statement

Allows you to include ASP. NET annotation statements in the body of the. aspx file. Any content between the start and end tags of the server annotation elements, whether ASP. NET code or text, will not be processed on the server or displayed on the result page.

 
 
  1. <%-- commented out code or content --%> 

Remarks

The ASP. NET Server-side annotation block has the same usage as a traditional language-specific annotation block, including documentation and testing ).

In the and <%> block, you can use the annotation syntax of the language that is used for encoding.

If you use the server-side ASP. NET annotation block in the <%> block, a compilation error occurs.

The start and end ASP. NET annotation mark can appear in the same line of code, or it can be separated by many commented-out lines.

The server comment block cannot be nested.

ASP. NET annotation example

The following example shows the HTML button control that has been commented out.

 
 
  1. <%-- <button runat="server" id="MyButton" OnServerClick="MyButton_Click"> 
  2.              Click here for enlightenment!  
  3.         button> 
  4.  --%>  

JScript Annotation

A single line JScript annotation starts with two forward slashes. The following is an example of a single line comment followed by a line of code.

 
 
  1. // This is a single-line comment. 
  2. AGoodIdea ="Comment your code for clarity .";
  3. Multiple lines of JScript comments with forward slashes and star numbers (/*), In the opposite order (*/.
  4. /* 
  5. This is a multiline comment that explains the preceding code statement. 
  6. The statement assigns a value to the aGoodIdea variable. The value, 
  7. Which is contained between the quote marks, is called a literal. 
  8. Literal explicitly and directly contains information; it does not 
  9. Refer to the information indirectly. The quote marks are not part 
  10. Of the literal. 
  11. */ 

If you try to embed another multi-line comment in one multi-line comment, JScript will explain the generated multi-line comment in an unexpected way. Mark the end of the embedded multi-line comment */will be interpreted as the end of the whole multi-line comment. Therefore, the text after the embedded multi-line comment will be interpreted as JScript code and may generate syntax errors.

In the following example, the third line of text is interpreted as JScript code because JScript interprets */in the innermost part as the end of the outermost comment:

 
 
  1. /* This is the outer-most comment  
  2. /* And this is the inner-most comment */ 
  3. ...Unfortunately, JScript will try to treat all of this as code. */ 

We recommend that you write all ASP. NET annotation statements as a single-line annotation block. In this way, you can use a multiline ASP. NET annotation to comment out a large code segment.

 
 
  1. // This is another multiline comment, written as a series of single-line comments.  
  2. // After the statement is executed, you can refer to the content of the aGoodIdea  
  3. // variable by using its name, as in the next statement, in which a string literal is  
  4. // appended to the aGoodIdea variable by concatenation to create a new variable.  
  5. var extendedIdea = aGoodIdea + " You never know when you'll have to figure out what it does."; 

Alternatively, you can use Conditional compilation to safely and effectively comment out large sections of code.

  1. Analysis on ASP. NET Web Security
  2. Session State of ASP. NET
  3. Analysis on the attribute ASP. NET of IsPostBack
  4. ASP. NET architecture and security mechanism
  5. Overview ASP. NET Crystal Reports

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.