Disabling cache for custom control
This MUST have been solved by someone, somewhere, but I can't seem to get around it.
I have a custom control, derived from SimpleView, which renders different content in it's template dependent upon the value inside a cookie. However, the caching kicks in and caches the output of the control on the first load and from then on, even if the cookie changes (and therefore should cause different content to be rendered), the same original content is displayed.
I have tried using the <asp:substitution> control, but this can't access the callback method in the class from within the template file.
I have tried putting <%@ OutputCache Duration="0" %> in the template file, but this has no effect.
To make the desired output show correctly I have switched off the caching on the page, which is not at all ideal as the page is noticably slower without caching.
Any help from some clever person out there would be great.
Hello JonnyP,
Can you try using the code below
protected
override
void
InitializeControls(GenericContainer container)
Context.Response.WriteSubstitution(
new
HttpResponseSubstitutionCallback(SubMethod));
public
static
string
SubMethod(HttpContext context)
return
string
.Empty;
Thanks, I had this same question and this seems to do the trick.
So is write subsitution the only way to do this our can one use the outputcache or Partial cache in the widget user control?
Using write subsitution is a pretty tricky method if you have complex widget and aren't just changing small text.
I figured out something that worked. I dropped this in my InitializeControls method in my widget. System.Web.
HttpContext.Current.Response.Cache.SetVaryByCustom("customfield");