OutputCache results in NullReferenceException

B

Bob

I have several simple user controls (e.g. header, footer) that have static
content so I thought it would be a good idea to turn on the ouput cache. So
I added <%@ OutputCache Duration="600" Shared="True" VaryByParam="none" %>
to the control. I have a base page class that overrides the Render() method
to load these controls:

protected override void Render(HtmlTextWriter writer) {
.........
LoadControl(Config.AppRoot +
"Ctrl/Header.ascx").RenderControl(writer);
.........

The above line throws System.NullReferenceException: Object reference not
set to an instance of an object. However, if I remove the OutputCache
directive, it works fine. Also if I put the user control in the page load
event handler rather than in the overriden Render method, it works fine too.
Does anyone know what the problem is? And how can I keep these common user
controls in the base page class, and at the same time take advantage of the
output cache feature?

Thanks
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top