I want to add a web user control to server-side cache using the following
code...
TextWriter tempWriter = new StringWriter();
Control control = LoadControl(acUrl);
control.RenderControl(new HtmlTextWriter(tempWriter));
sb.Append(tempWriter.ToString());
Context.Cache.Insert(acUrl, sb.ToString(), null,
DateTime.Now.AddSeconds(seconds), TimeSpan.Zero);
It works, almost! The web user control's code behind doesn't run and as a
result only the raw ascx file gets cached. I've seen Portals use this form
of caching because it offers awesome control. But they typically subclass the
user control and override the control's prerender and render methods when
caching. I'm trying to take a shortcut and cache the user control directly
from the ASPX form. Please let me know if you have any ideas.
Mike

Signature
mcp, mcse, mcsd, mcad.net, mcsd.net
[MSFT] - 11 Aug 2004 09:13 GMT
Hi Mike,
In this way, you just put a string in the ASP .NET cache, not the web
control. I think we have to subclass the web control and override its
render method. Then, get the string from cache and use as result of render
method, instead of rendering the control actually.
Luke