|
ASP.NET provides a mechanism for caching portions of pages, called page fragment caching. To cache a portion of a page, you must first encapsulate the portion of the page you want to cache into a user control. In the user control source file, add an OutputCache directive specifying the Duration and VaryByParam attributes. When that user control is loaded into a page at runtime, it is cached, and all subsequent pages that reference that same user control will retrieve it from the cache.
<!— UserControl.ascx —>
<%@ OutputCache Duration='60' VaryByParam='none' %> <%@ Control Language="'C#'" %>
<script runat="server"> protected void Page_Load(Object src, EventArgs e) { _date.Text = "User control generated at " + DateTime.Now.ToString(); } </script> <asp:Label id='_date' runat="'server'" />
Here I have user caching on user control, so when ever we used in a page , only partial page will be cached.
http://kalitinterviewquestions.blogspot.com/
|