Substitution control

Substitution control

Previous Home Next

 

There was no way to control which parts of a page would be cached, and more importantly: Which parts would be generated on each request no matter what. That meant that whenever you needed just a small part of the page to refreshed on each request, the OutputCache directive could not be used. This has changed with ASP.NET 2.0, where we may use the  tag to make areas exist outside the cached content.

 
  

<%@ OutputCache Duration="20" VaryByParam="none"%>Page Cache For 20 second.
 Subsititution Cotrol Syntax,GetFreshDateTime method needs to be called by the Substitution control.
(.CS) HttpContext allows you to access all kinds of information about the request etc. to use for returning the proper value. For now, we simply return the current datetime. Run the example, and see how the first date is cached, while the second is reloaded each time.

 Subsititution Design Code
**************************************************************************
**************<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Substitution.aspx.cs" Inherits="_Default" %>
<%@ OutputCache Duration="20" VaryByParam="none"%>




    Substitution


    

Real Time is:

*********************************************************************** .CS 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) { shw_date.Text = "The Time is: " + DateTime.Now.ToString(); } protected static string GetFreshDateTime(HttpContext context) { return DateTime.Now.ToString(); } }
Previous Home Next