您的位置:首页 > 其它

substitution控件:在页面输出缓存状态,保持部分数据的动态更新

2007-12-12 23:32 676 查看
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void Page_Load(object sender, EventArgs e)

{

//缓存整个页面,采用页面输出缓存一样达到同样的效果

//<%@ OutputCache Duration="60" VaryByParam="none" %>

Response.Cache.SetExpires(DateTime.Now.AddSeconds(40));

Response.Cache.SetCacheability(HttpCacheability.Public);

//Response.Cache.SetValidUntilExpires(true);

}

private static string getTime(HttpContext context)

{

return DateTime.Now.ToString();

}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

substitution控件可以让缓存的页面部分刷新,从而保持部分数据的动态更新。<br />

该时间将被缓存:<%= DateTime.Now.ToString() %><br />

尽管整个页面被缓存,但是下面的时间却不会,因为我们用了substitution控件。<br />

当前时间:

<span style="color:Red; font-weight:bold;"><asp:Substitution ID="subTime" runat="server" MethodName="getTime" /></span> <br />

给Substitution控件的属性<i><b>MethodName</b></i>指定一个带<i><b>HttpContext参数</b></i>的<i><b>静态方法</b></i>,<br />

返回的数据将在该控件中显示。<br />

<span style="color:Blue;">private <b>static</b> string getTime(<b>HttpContext</b> context)</span>

<br />

</div>

</form>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐