< % for(int i=0;i<10;i++) { Reaponse.Write(i.ToString()); } %>
<asp:Label ID="lblId" runat="server" Text='<%#Eval("title") %>' Visible="false"></asp:Label>
用來綁定後臺的變量或方法且有返回值 的,但此時的變量名或方法的訪問修飾符爲protected或publicweb
<%=name%> <%=getstr()%>
<%@ import namespace="system.data">
<asp:TextBox runat="server" ID="cc" Text="<%$ ConnectionStrings:pubs%>"></asp:TextBox> web.config <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <connectionStrings> <add name="pubs" connectionString="Server=.;database=pubs;uid=sa;pwd=" providerName="System.Data.SqlClient"/> </connectionStrings> </configuration>
這種方式是ASP.NET4.0中新加入的綁定方式,經常使用於MVC中,但普通webform中也可以使用。功能其實就是對綁定的值進行一下編碼,所以,一下二者是等同的:服務器
<%= Server.HtmlEncode("<b>test</b>") %> <%: "<b>test</b>" %>;