开发者

UpdatePanel with browser caching

I recently learned that the UpdatePanel uses HTTP requests with the "no-cache" header added. This causes images inside it to be downloaded on every UpdatePanel update. I do not want this.

So how do I prevent this?

I've thought about extending the UpdatePanel control and try scraping out the "no-cache"-part of the requests, but surely there mus开发者_Go百科t be a more elegant solution.


Replace the contents of the panel manually using jquery. I have done this quite a bit. The pattern I generally use is using a user control, and then capture the text using code like this:

var stringBuilder = new StringBuilder();
using (var tw = new TextWriter())
{
       var htmlWriter = new HtmlWriter(tw);

       userControl.RenderControl(htmlWriter);

       return stringBuilder.ToString();
}

This is the result I return to the PageMethod, I set the html in the specified div, and bang - you're done.

Like so many things in development, you'll eventually hit a wall with the automated tools, and you have to pop down a level in abstraction to make it work. Good luck!


The UpdatePanel will only put the no-cache header on its own request for the update, not on requests to other resources like images. Those are handled by the browser like regular requests, even if they're inside the UpdatePanel content.
Perhaps you simply forgot to put an Expires header on your image?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜