复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ outputcache duration="10" varybyparam="none" %>
<!--设置缓存时间为10秒-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head runat="server">
<title>Substitution控件实例</title>
</head>
<body>
<form runat="server">
<h1>Substitution控件实例演示</h1>
您好<b>
<asp:substitution methodname="GetUser" runat="Server">
</asp:substitution></b><br>
当前时间[非缓存]:
<b><asp:Substitution runat="server" MethodName="GetTime" /></b>
<br />
缓存: <%=DateTime.Now.ToLongTimeString() %>
<asp:Button runat="server" Text="刷新" />
</form>
</body>
</html>
复制代码 代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
//下面定义了两个表态方法,可以使用Substitution控件调用,以实现这两个方法每次刷新时都要调用
public static string GetUser(HttpContext context)
{
return context.User.Identity.Name;
}
public static String GetTime(HttpContext context)
{
return DateTime.Now.ToString();
}
}
新闻热点
疑难解答
图片精选