Post cache substitution is used when we want to cache the whole page but be also need some dynamic region inside that cached page. Some examples like QuoteoftheDay, RandomPhotos, and AdRotator etc. are examples where we can implement Post Cache Substitution.
Post-cache substitution can be achieved by two means:
- Call the new Response.WriteSubstitution method, passing it a reference to the desired substitution method callback.
- Add a <asp:Substitution> control to the page at the desired location, and set its methodName attribute to the name of the callback method.
You can see we have a static function here “GetDateToString()”. We pass the response substitution callback to the “WriteSubstitution” method. So now, when ASP.NET page framework retrieves the cached page, it automatically triggers your callback method to get the dynamic content. It then inserts your content into the cached HTML of the page. Even if your page has not been cached yet (for example, it's being rendered for the first time), ASP.NET still calls your callback in the same way to get the dynamic content. So you create a method that generates some dynamic content, and by doing so you guarantee that your method is always called, and it’s content is never cached.
Ok the below example was by using “WriteSubstitution” now let’s try to see how we can do by using “<asp:substitution>” control. You can get the “<asp:substitution>” control from the editor toolbox.
Below is a sample code that shows how substitution control works. We have ASPX code at the right hand side and class code at the behind code at the left hand side. We need to provide the method name in the “methodname” attribute of the substitution control.
Above is the ASP.NET interview questions & see the following video on Postback,Ispostback & Autopostback: -
write a comment