📜 ⬆️ ⬇️

Problem when using OutputCache in CustomControl

Working on a single project on asp.net, I encountered an unpleasant problem when using the cache in CustomControl. When using this type of caching:
<%@ OutputCache Duration="86400" VaryByParam="MenuID" %>

* This source code was highlighted with Source Code Highlighter .

during PostBack, I got invalid data from the cache. For a long time I could not understand why this was happening, I shoveled a bunch of code, and then I thought that this could be a bug. I searched the Internet for different forums and found a solution.

The solution turned out to be very simple - just add the hidden input to the control:
<%@ OutputCache Duration= "86400" VaryByParam= "MenuID" %>

<input type= "hidden" name= "MenuID" value = "<%= Request.QueryString[" MenuID "] ?? " 0 " %>" />


* This source code was highlighted with Source Code Highlighter .

After that, everything worked as it should. I really do not know this bug or feature =)
I hope it will help someone.

UPD: VaryByParam - sets conditional caching based on the values ​​of the query string during GET or parameters during POST. Values ​​must be separated by a semicolon. It seems that conditional caching occurs only on the server, because regardless of the value of VaryByParam in the Vary http-header is "*". VaryByParam - required to be specified if the VaryByControl attribute is not specified. VaryByParam can be equal to “none” and then conditional on caching parameters does not occur, or VaryByParam can be equal to “*” and then conditional caching is performed on all parameters.
Thank you XaocCPS

')

Source: https://habr.com/ru/post/45967/


All Articles