Substitutioncontrol example
Previous | Home | Next |
One of the new controls introduced with ASP.NET 2.0 was the Substitution control. By using this control, you can create pages that participate in output caching but also have regions designated to contain dynamic content that will be updated on every page request. This type of setup is referred to as Post-Cache Substitution (or Donut Caching) and is aimed at optimizing the development experience for this mostly-cached page scenario. Rather than requiring page developers to mark page regions (user controls) as cached, post-cache substitution allows them to output cache an entire page and then simply identify regions of the page that should be exempt from caching. It also allows control developers to prevent their rendering from being cached. For example, an AdRotator control that takes advantage of post-cache substitution would be able to serve a different advertisement on each request even if its parent page were cached.
The method to which the Substitution control is bound is specified via the MethodName property. That method must meet the following criteria: * It must be a static (shared in VB) method. * It accepts one parameter of type HttpContext. * It returns a string representing the markup that should replace the control on the page.
..........................Design Code............................... .....................................................................<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ OutputCache Duration="10" VaryByParam="none" %>.................................................................... .....................source code.................................... using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToLongTimeString(); } public static string GetUpdatedTime(HttpContext context) { return DateTime.Now.ToLongTimeString(); } protected void Button1_Click(object sender, EventArgs e) { } } ....................................................................Untitled Page
Previous | Home | Next |