<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default_aspx" %>
<%@ Register TagPrefix="MyUserControl" TagName="LoadTime" Src="~/Control.ascx"%>
Fragment Caching
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default_aspx : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblTime.Text = "This page was loaded at " +
DateTime.Now.ToLongTimeString();
}
}
File: Control.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Control.ascx.cs" Inherits="SimpleUserControl_ascx" %>
<%@ OutputCache Duration="10" VaryByParam="*" %>
User Control
File: Control.ascx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class SimpleUserControl_ascx : System.Web.UI.UserControl
{
public string UserName
{
get
{
return lblUserName.Text;
}
set
{
lblUserName.Text = value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
lblTime.Text = "This user control was loaded at " +
DateTime.Now.ToLongTimeString();
}
protected void btn_Click(object sender, EventArgs e)
{
lblUserName.Text = "Jesse";
}
}