详解ASP.NET注释语句及服务器注释
创始人
2024-04-22 13:31:06
0

服务器端ASP.NET注释语句

允许您将ASP.NET注释语句包括在 .aspx 文件的正文中。服务器端注释元素的开始标记和结束标记之间的任何内容,不管是 ASP.NET 代码还是文本,都不会在服务器上进行处理或呈现在结果页上。

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

备注

ASP.NET服务器端注释块与传统的语言特定注释块具有相同的用法(包括文档和测试)。

在 和 <% %>块中,可以使用正用于编码的语言的注释语法。

如果在 <% %>块中使用服务器端ASP.NET注释块,则会出现编译错误。

开始和结束ASP.NET注释标记可以出现在同一行代码中,也可以由许多被注释掉的行隔开。

服务器端注释块不能被嵌套。

ASP.NET注释示例

下面的示例说明被注释掉的 HtmlButton 控件。

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

JScript 注释

单行 JScript 注释以两个正斜杠 (//) 开始。以下是单行注释(后跟一行代码)的一个示例。

  1. // This is a single-line comment.  
  2. aGoodIdea = "Comment your code for clarity.";  
  3. 多行 JScript 注释以正斜杠和星号 (/*) 开头,以相反的顺序 (*/) 结束。  
  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. A  
  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. */ 

如果试图在一个多行注释中嵌入另一个多行注释,JScript 将以一种意想不到的方式解释生成的多行注释。标记嵌入的多行注释结尾的 */ 将被解释为整个多行注释的结尾。因此,在嵌入的多行注释后面的文本将被解释为 JScript 代码,并可能生成语法错误。

在下面的示例中,由于 JScript 将最里面的 */ 解释为最外面注释的结尾,因此第三行文本将被解释为 JScript 代码:

  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. */ 

建议将所有ASP.NET注释语句编写为单行注释的块。这样就允许随后用一个多行ASP.NET注释来注释大段代码。

  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."

或者还可以使用条件编译安全有效地注释大段代码。

【编辑推荐】

  1. 浅析ASP.NET Web 安全性
  2. ASP.NET的Session State
  3. 浅析IsPostBack属性ASP.NET
  4. ASP.NET构架与安全机制
  5. 概述ASP.NET水晶报表

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...