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.
- <%-- 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.
- <%-- <button runat="server" id="MyButton" OnServerClick="MyButton_Click">
- Click here for enlightenment!
- button>
- --%>
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.
- // This is a single-line comment.
- AGoodIdea ="Comment your code for clarity .";
- Multiple lines of JScript comments with forward slashes and star numbers (/*), In the opposite order (*/.
- /*
- This is a multiline comment that explains the preceding code statement.
- The statement assigns a value to the aGoodIdea variable. The value,
- Which is contained between the quote marks, is called a literal.
- Literal explicitly and directly contains information; it does not
- Refer to the information indirectly. The quote marks are not part
- Of the literal.
- */
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:
- /* This is the outer-most comment
- /* And this is the inner-most comment */
- ...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.
- // This is another multiline comment, written as a series of single-line comments.
- // After the statement is executed, you can refer to the content of the aGoodIdea
- // variable by using its name, as in the next statement, in which a string literal is
- // appended to the aGoodIdea variable by concatenation to create a new variable.
- 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.
- Analysis on ASP. NET Web Security
- Session State of ASP. NET
- Analysis on the attribute ASP. NET of IsPostBack
- ASP. NET architecture and security mechanism
- Overview ASP. NET Crystal Reports