I have a user control that should use caching, c VaryByControl. The file is .ascxas follows:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="mynamespace.TestControl" %>
<%@ OutputCache Duration="10" Shared="true" VaryByControl="Test" %>
<p id="SomeText" runat="server">Nothing</p>
The class TestControlin the code file has a property int Test {...}and an event handler Page_Load()that fills the paragraph SomeText:
SomeText.InnerText = string.Format(@"Test={0} at {1}", Test, DateTime.Now)
I have a file .aspxthat looks like this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="mynamespace.TestPage" %>
<%@ Register TagPrefix="xxx" TagName="TestControl" Src="Controls\TestControl.ascx" %>
<!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>
<xxx:TestControl Test="6" runat="server" />
<xxx:TestControl Test="7" runat="server" />
<hr />
<asp:PlaceHolder ID="Suport" runat="server" />
</body>
</html>
Two tags <xxx:TestControl>correctly load instances TestControlwith Testset to the expected value, I can update the browser several times, and I see how the cache does this job correctly.
<asp:PlaceHolder ID="Suport" /> TestControl, Test, . LoadControl, Test. , , asp.net .aspx . , , PartialCachingControl CachedControl , TestControl Test 0.
.aspx Page_Load():
protected void Page_Load(object sender, EventArgs e)
{
PartialCachingControl tc = (PartialCachingControl) LoadControl(@"Controls\TestControl.ascx");
if (tc.CachedControl != null)
((TestControl)tc.CachedControl).Test = 67;
Suport.Controls.Add(tc);
}
, , , . , ASPX , ( ).
2
, . , , .