转自 Love小脚丫
1. <%--exegesics--%> 注释
//相当于<!---->
- <%--注释--%>
2. <% code%> 绑定后台代码块:
//相当于写在后台的可执行代码
<form id="form1" runat="server"> <%--绑定后台代码块--%> <% for (int i = 1; i <= 10; i++) { %> <%=i %> <%} %> </form>
3.<%= variable %> 绑定 后台变量:
//还可以绑定后台方法<%=NewMethod()%> 也可以写作<%:variable %>
- <form id="form1" runat="server">
- <%=_title %>
- </form>
Code behind
namespace WebApplication { public partial class Index : System.Web.UI.Page { public string _title = ""; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { _title = "标题"; } } } }
4.<%# Eval("field")%>绑定DataSource的值
<form id="form1" runat="server"> <asp:Repeater ID="Repeater" runat="server"> <ItemTemplate> <span><%# Eval("name") %></span> </ItemTemplate> </asp:Repeater> </form>
code behind
- this.Repeater.DataSource = null;
5.<%$ %> 绑定web.config的值
<form id="form1" runat="server"> <asp:Literal ID="Literal1" runat="server" Text="<%$appSettings:upload_image_path%>" /> </form>
web.config
<configuration> <appSettings> <add key="upload_image_path" value="/upload/images/"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> </configuration>
6. <%@ %>主要用于在web页面定义Page、引入控件、组件、设置Cache等:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="benben.Index" %>
时间: 2024-10-12 04:35:37