File 1:deafault.aspx
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%>
<%@ OutputCache duration= "Ten" varybyparam= "None"%>
<!--set cache time to 10 seconds-->
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>substitution Control Instance </title>
<body>
<form id= "Form1" runat= "Server" >
Hello <b>
<asp:substitution id= "M1" Methodname= "GetUser" runat= "Server" >
</asp:substitution></b><br>
Current time [not cached]:
<b><asp:substitution id= "m2" runat= "server" Methodname= "GetTime"/></b>
<br/>
Caching: <%=datetime.now.tolongtimestring ()%>
<asp:button id= "Button1" runat= "Server" text= "Refresh"/>
</form>
</body>
File 2:deafault.aspx.cs
Copy Code code as follows:
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; The
public partial class _default:system.web.ui.page
{
//below defines two gesture methods that can be invoked using the substitution control to implement the two method to call the
public static string GetUser (HttpContext context)
{
Return context each time it is refreshed. User.Identity.Name;
}
public static String GetTime (HttpContext context)
{
return DateTime.Now.ToString ();
}
}