开发者

How to stop page execution from inside a Web Part

(I believe that this applies to both normal ASP.NET web parts and SharePoint hosted web parts)

The web part has an 'export' button that renders the output as csv and sets the appropriate headers so its opened in Excel.

Hooking in the buttons click event, clearing the response, adding the appropriate headers and content types is trivial - example

However I've noticed that if this code added to a web part and a debugger attached then if there are multiple i开发者_JAVA技巧nstances of this (or any other) web part on the page then neither HTTPApplication.CompleteRequest or Response.End stop the processing/page lifecycle and all the events for all the page controls still fire.

This is wasteful in this example as the other web parts don't need to run - nothing they do will get to the response.

Any way of stopping other web parts being rendered?


What about creating another page that does the actual export function for you, then have the export link merely link to this other page?

This should solve the problem of having to end the request manually, since you can control exactly what is output in the response.


Short answer: no.

Since you're doing full postbacks, HTTP response stream must contain the entire HTML page that was delivered by the server.

You can use ASP.NET output caching and refresh cache by some parameter, allowing your page to render such web parts that have their data changed.

Learn more about ASP.NET caching reading this documentation:

  • http://msdn.microsoft.com/en-us/library/xsbfdd8c(v=VS.100).aspx


HttpContext.Current.Response.End();

Is only for compatibility with ASP.

ApplicationInstance.CompleteRequest();

is supposed to do what you want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜