Substitution.MethodName 属性

命名空间:System.Web
程序集:System.Web(在 system.web.dll 中)

<script type="text/Javascript"> var ExpCollDivStr=ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl025f246c3,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl02img,"; </script> 语法
Visual Basic(声明)
Public Delegate Function HttpResponseSubstitutionCallback ( _
    context As HttpContext _
) As String
Visual Basic(用法)
Dim instance As New HttpResponseSubstitutionCallback(AddressOf HandlerMethod)
C#
public delegate string HttpResponseSubstitutionCallback (
    HttpContext context
)
C++
public delegate String^ HttpResponseSubstitutionCallback (
    HttpContext^ context
)
J#
/** @delegate */
public delegate String HttpResponseSubstitutionCallback (
    HttpContext context
)
JScript
JScript 支持使用委托,但不支持进行新的声明。

 

参数
context

包含对页的 HTTP 请求信息的 HttpContext,该页带有需要缓存后替换的控件。

 

 

返回值
在发送到客户端之前插入到缓存的响应的内容。
<script type="text/Javascript"> var ExpCollDivStr=ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl10cf22bea,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl10img,"; </script> 备注

HttpResponseSubstitutionCallback 委托用于 WriteSubstitution 方法,可呈现 SubstitutionAdRotator 控件缓存后内容。

对于 Substitution 控件,则使用 MethodName 属性来指定要在 Substitution 控件执行时调用的回调方法的名称。您指定的回调方法必须是包含 Substitution 控件的页或用户控件上的静态方法。回调方法的签名必须与接受 HttpResponseSubstitutionCallback 参数并返回字符串的 HttpContext 委托的签名匹配。

对于 AdRotator 控件,除非为 AdCreated 事件提供了事件处理程序,否则该控件的呈现不受页缓存的影响。如果未提供 AdCreated 事件处理程序,则使用缓存后替换来呈现 AdRotator 内容。

<script type="text/Javascript"> var ExpCollDivStr=ExpCollDivStr; ExpCollDivStr = ExpCollDivStr + "ctl00_LibFrame_ctl17ec5486b,"; var ExpCollImgStr = ExpCollImgStr; ExpCollImgStr = ExpCollImgStr + "ctl00_LibFrame_ctl17img,"; </script> 示例

下面的代码示例演示如何以编程方式将 Substitution 控件添加到输出缓存网页。加载页面时,将在一个标签中向用户显示当前的日期和时间。页面中的此区域每 60 秒缓存并更新一次。当 Substitution 控件执行时,它调用 GetCurrentDateTime 方法,该方法必须匹配 HttpResponseSubstitutionCallback 委托的签名。GetCurrentDateTime 方法返回的字符串将显示给用户。每次刷新页时,都不会缓存和更新页中的这一部分。Substitution 控件的 MethodName 属性获取或设置回调方法的名称。

Visual Basic
<%@ outputcache duration="60" varybyparam="none" %>
<script runat="server" language="VB">  
  
  Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Programmatically create a Substitution control.
    Dim Substitution1 As New Substitution
    
    ' Specify the callback method.
    Substitution1.MethodName = "GetCurrentDateTime"
    
    ' Add the Substitution control to the controls
    ' collection of PlaceHolder1.
    PlaceHolder1.Controls.Add(Substitution1)
    
    ' Display the current date and time in the label.
    ' Output caching applies to this section of the page.
    CachedDateLabel.Text = DateTime.Now.ToString()
  End Sub
  
  ' The Substitution control calls this method to retrieve
  ' the current date and time. This section of the page
  ' is exempt from output caching. 
  Shared Function GetCurrentDateTime(ByVal context As HttpContext) As String
    Return DateTime.Now.ToString()
  End Function
  
</script>

<html>
<head id="Head1" runat="server">
  <title>Substitution Constructor Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution Constructor Example</h3>  
    
    <p>This section of the page is not cached:</p>
    <asp:placeholder id="PlaceHolder1"
      runat="Server">
    </asp:placeholder>
    
    <br />
    
    <p>This section of the page is cached:</p>
    
    <asp:label id="CachedDateLabel"
      runat="Server">
    </asp:label>
    
    <br /><br />
    
    <asp:button id="RefreshButton"
      text="Refresh Page"
      runat="Server">
    </asp:button>     

  </form>
</body>
</html>
<%@ outputcache duration="60" varybyparam="none" %>
<script runat="server" language="C#">  
  
  void Page_Load(object sender, System.EventArgs e)
  {
    // Programmatically create a Substitution control.
    Substitution Substitution1 = new Substitution();
    
    // Specify the callback method.
    Substitution1.MethodName = "GetCurrentDateTime";
    
    // Add the Substitution control to the controls
    // collection of PlaceHolder1.
    PlaceHolder1.Controls.Add (Substitution1);        

    // Display the current date and time in the label.
    // Output caching applies to this section of the page.
    CachedDateLabel.Text = DateTime.Now.ToString();    
  }
  
  // The Substitution control calls this method to retrieve
  // the current date and time. This section of the page
  // is exempt from output caching. 
  public static string GetCurrentDateTime (HttpContext context)
  {
    return DateTime.Now.ToString ();
  }
  
</script>

<html>
<head id="Head1" runat="server">
  <title>Substitution Class Example</title>
</head>
<body>
  <form id="Form1" runat="server">
  
    <h3>Substitution Constructor Example</h3>  
    
    <p>This section of the page is not cached:</p>
    <asp:placeholder id="PlaceHolder1"
      runat="Server">
    </asp:placeholder>
    
    <br />
    
    <p>This section of the page is cached:</p>
    
    <asp:label id="CachedDateLabel"
      runat="Server">
    </asp:label>
    
    <br /><br />
    
    <asp:button id="RefreshButton"
      text="Refresh Page"
      runat="Server">
    </asp:button>     

  </form>
</body>
</html>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值