zoukankan      html  css  js  c++  java
  • substitution控件:在页面输出缓存状态,保持部分数据的动态更新

    <%@ 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>
  • 相关阅读:
    hdu 1532(最大流)
    星沉月朗
    uva 818 (位运算 + 判环)
    SQL变量、Substring、charindex、case函数、去除重复
    C# Tostring格式
    asp.net导出word(word2007)
    asp.net生成缩略图
    正则表达式语法
    解压缩
    文件复制
  • 原文地址:https://www.cnblogs.com/flaaash/p/992874.html
Copyright © 2011-2022 走看看