Friday 24 February 2012

Implementation of fragment caching in asp.net

Lets first create a user control.

ASCX PAGE

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CahceUserControl.ascx.cs"

Inherits="CahceUseControl" %>

<%@ OutputCache Duration="5" VaryByParam="None" %>



<p><asp:Label ID="lblTime" runat="server" EnableViewState="false"

ForeColor="GradientActiveCaption" /></p>

ASCX CODE BEHIND
protected void Page_Load(object sender, EventArgs e)

{
lblTime.Text = DateTime.Now.ToString();
}
Now create a .aspx page.
ASPX PAGE
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CahcedControl.aspx.cs"

Inherits="CahcedControl" %>

<%@ Register Src="~/CahceUserControl.ascx" TagPrefix="uc1"  
TagName="UserControl" %>

<!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">

     <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

         Try to refresh this page, the Date time doesn't change. 
Keep refreshing and after

5 seconds you should see the change in time. <uc1:UserControl runat="server" ID="uc11" />

    </div>

    </form>

</body>

</html>

No comments:

Post a Comment