ASP.NET <% %>的各種形式用法

來源:互聯網
上載者:User

標籤:bsp   控制項   ted   net   text   訪問   system   後台   orm   

1.<% %>用來綁定後台代碼
< %for(int i=0;i<10;i++){Reaponse.Write(i.ToString());}%>
2、<%# %> 是在繫結控制項DataBind()方法執行時被執行,用於資料繫結
<asp:Label ID="lblId" runat="server" Text=‘<%#Eval("title") %>‘ Visible="false"></asp:Label>

 

3、<%= %>是在用戶端擷取伺服器端的變數,後台往前台傳值

用來綁定背景變數或方法且有傳回值 的,但此時的變數名或方法的存取修飾詞為protected或public

 

<%=name%> <%=getstr()%>

 

4、<%@ %>用來匯入後台命名空間
<%@ import namespace="system.data">

 

5、<%$ %>用來綁定web.config裡的字串(索引值對)
<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>

 

6、<%: %>

這種方式是ASP.NET4.0中新加入的綁定方式,常用於MVC中,但普通webform中也可使用。功能其實就是對綁定的值進行一下編碼,因此,一下兩者是等同的:

<%= Server.HtmlEncode("<b>test</b>") %><%: "<b>test</b>" %>;

 

ASP.NET <% %>的各種形式用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.