asp.net 中<% %>、<%@ %>、<%# %>、<%= %>、<%$ %>的用法
转自 Love小脚丫
1. <%--exegesics--%> 注释
//相当于<!---->
- <%--注释--%>
//相当于写在后台的可执行代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<form id="form1" runat="server"> <%--绑定后台代码块--%> <% for (int i = 1; i <= 10; i++) { %> <%=i %> <%} %> </form>
//还可以绑定后台方法<%=NewMethod()%> 也可以写作<%:variable %>
- <form id="form1" runat="server">
- <%=_title %>
- </form>
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
namespace WebApplication { public partial class Index : System.Web.UI.Page { public string _title = ""; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { _title = "标题"; } } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<form id="form1" runat="server"> <asp:Repeater ID="Repeater" runat="server"> <ItemTemplate> <span><%# Eval("name") %></span> </ItemTemplate> </asp:Repeater> </form>
- this.Repeater.DataSource = null;
<form id="form1" runat="server"> <asp:Literal ID="Literal1" runat="server" Text="<%$appSettings:upload_image_path%>" /> </form>
web.config![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<configuration> <appSettings> <add key="upload_image_path" value="/upload/images/"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> </configuration>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="benben.Index" %>