2010-09-28 98 views
8

我们在哪里使用<%@ %><%= %><%# %>等 什么其他asp标签可以添加到asp.net网页?如何在ASP.NET网页中嵌入代码块?

+0

可能重复的[ASP.NET“特殊”标记](http://stackoverflow.com/questions/649428/asp-net-special-tags) – 2010-09-28 11:47:23

回答

0
<%@ %> - page directives, Register control 
<%= %> - for the server code 
<%# %> - for the eval kind of function its also for the server code 
+0

那么为什么这不给任何输出Text ='<%= DateTime.Now.ToShortTimeString()%>' – ppp 2010-09-28 11:50:11

+0

@ppp它将值赋给控件表单内联编码 – 2010-09-28 11:52:55

+0

@Rana表示?如何使用此标签将当前日期时间的标签值设置为? – ppp 2010-09-28 11:56:30

15

<%%>短手:所述<%%>是服务器端代码内

<script runat="server"> 
</script> 

点儿。

其他变型也是快捷键:

  • <%@%>是页面directrive
  • <%=%>是短期的Response.Write
  • <%:%>短为Response.Write,加入HTML编码(与.NET 4.0引入)
  • <%#%>是结合表达

This page对所有这些都是很好的参考。