Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
All ASP .NET Text Articles
All ASP .NET Slides
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In Part 122 of the asp.net video tutorial, we discussed about fragment caching. Please watch Parts 122 before proceeding with this video. In this video we will discuss about, caching multiple versions of user control using VaryByControl attribute of the "OutputCache" directive.
We will be using tblProducts table for this demo. If you need the script to create and populate this table, please refer to Part 122, by clicking here.
Link for code samples used in the demo
Caching multiple responses of a user control declaratively, using "VaryByControl" attribute of the "OutputCache" directive
To cache multiple response of the user control, include "OutputCache" in the aspx of the UCProductsControl.ascx. VaryByControl"DropDownList1", indicates that a separate response must be cached for each varying value in DropDownList1.
Caching multiple responses of a user control programatically, using "VaryByControls" property of the PartialCachingAttribute
We can also achieve the same thing, by specifying "PartialCachingAttribute" on the UCProductsControl class as shown below.
public partial class UCProductsControl : System.Web.UI.UserControl
//.Rest of the UCProductsControl code
Please run the application and test. Notice that, as the product selections change in the dropdownlist, for each different selection a response from the user control is cached for 60 seconds. The difference between "User Control Server Time" and "User Control Client Time" proves this. Since, we don't have "Caching" set on the WebForm1.aspx, "Page Server Time" and "Page Client Time" stays the same always.
In our next video, we will discuss about when and how to use "VaryByParams" to cache multiple versions of a user control.