1
<h2>Welcome</h2><ul><% for (int i = 0; i <= Convert.ToInt32(ViewData["numtime"]); i++) {%><li><%= ViewData["Message"].ToString() %></li><% } %> </ul>
"{" 是语言的一部分,肯定要写在 <%%>中
二、 指令(<%@%>)
Master,Page,Control,Impot,Assembly,Reference等
<%@Master%>
适用文件: master (母版页)
例子:<%Master Language="C#" AutoEventWireup="true" CodeFile="BalloonShop.master.cs" Inherits="BalloonShop"%>
<%@Page%>
适用文件: aspx (aspx页)
例子:<% Page Title="" Language="C#" MasterPageFile="~/BalloonShop.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"%>
Page Title="Hello World" Language="C#" MasterPageFile="~/BalloonShop.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"
<%@Control%>
适用文件: ascx (用户控件)
例子:
Control Language="C#" AutoEventWireup="true" CodeFile="DepartmentList.ascx.cs" Inherits="UserControls_DepartmentList"
<%@Register%>
适用文件:master,aspx,ascx
作用:用于注册ascx控件
例子:
<%@ Register Src="~/UserControls/DepartmentList.ascx" TagName="DepartmentList" TagPrefix ="myAscx" %>
<div class="Left">
<myAscx:DepartmentList ID="DepartmentList" runat="server"/>
……
<%@Import%>
作用:导入命名空间
适用文件:aspx,ascx,master
例子:
<%@Import Namespace="BalloonShopBLL"%>
<%@Assembly%>
适用文件:aspx,ascx,master,asax
作用:将程序集链接到 应用程序页(例如网页、用户控件、母版页或 Global.asax 文件),使程序集的所有类和接口都在该页上可用。(类似于Import)
<%@OutputCache%>
适用文件:ascx,aspx
作用:在aspx页或者ascx中设置缓存策略
<%@Reference%>
适用文件:mater,aspx,ascx
作用:用于链接另一个文件(aspx,ascx等),链接后可用 Page.LoadControl 方法进行加载。
<%@PreviousPageType%>
作用:指令用于跨页传递
<%@MasterType%>
作用:当通过 Master 属性访问 母版页时,创建对该母版页的强类型引用。
<%@Implements%>
适用文件:ascx,aspx,master
作用:当前页中要实现哪些.NET接口