Search

Sunday, February 2, 2014
0 comments

How to use Substitution Control in ASP.NET

3:36 AMSunday, February 2, 2014
The substitution control is used to specify a section on an output-cached Web page where you want to substitute the dynamic content for the control. This control provides a simplified solution to partial page caching for pages where the majority of the content is cached. You can output  cache the entire page, and then use the Substitution control to specify the sections of the page that are exempted from caching.

Public Properties of the Substitution class

MethodName : Callback method to call up when the Substitution control executes.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="substitution.aspx.cs" Inherits="substitution" %>
<%@ OutputCache Duration="300" VaryByParam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script runat="server">  
    static string dotprogramming(HttpContext context) {

        string name = DateTime.Now.ToString();
        return name;
          
    }  
</script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Page Cached DateTime<br />
&nbsp; <%= DateTime.Now.ToString() %> 
        <br />
        Current Time without cache<br />
&nbsp;<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
        <asp:Substitution ID="Substitution1" runat="server" 
            MethodName="dotprogramming" />
    </div>
    </form>
</body>
</html>

In this example page cached for 300 seconds using OutputCache directive , But you can refresh content using Substitution control.
Code Generate the following Output
How to use Substitution Control in ASP.NET

How to use Substitution Control in ASP.NET

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top