中国搜 程序源代码学习 编程源代码 直接应用在编程实践中 优秀编程书籍源码欣赏

收藏本页到>> 新浪ViVi  365Key网摘   IE收藏夹 |设为首页

 中国搜首页 >>ASP.NET相关>>内嵌代码和内嵌表达式 C#版

代码说明:
     ASP.NET的一个重要限制是页面内只能包含一个<form runat="server" >标记。如果需要在HTML或者文本内容中执行代码的话,就可以使用代码呈现块来实现。代码呈现块有两类:内嵌代码(inline code)和内嵌表达式(inline expression).内嵌代码执行一条或者几条语句。内嵌表达式可以显示变量或者方法的值。它们均以<%= 字符开始,以%>字符结束。
    下面的代码演示了如何在ASP.NET页面中同时使用内嵌表达式和内嵌代码。

<Script Runat="Server">
Dim strSomeText As String
Sub Page_Load
strSomeText = "Hello!"
End Sub
</Script>

<html>
<head><title>CodeRender.aspx</title></head>
<body>
<form Runat="Server">
The value of strSomeText is:
<%=strSomeText%>

<p>

<% strSomeText = "Goodbye!" %>
The value of strSomeText is:
<%=strSomeText%>
</form>
</body>
</html>

   运行演示程序   

  ©2004   www.zhonguosou.com