问题
I have a home page on a website (ASP.NET 4.0 C#) which loads a lot of data every time it is accessed (basically a dashboard). This can (depending on the user) take a while to load, so I broke each section into update panels and load them separately so that the user can see it loading and not just think it the page has frozen. However this presents new issues because if the user does not want to wait and clicks on the navigation menu (or a link) to a different page, they have to wait until the page has fully loaded before it moves on.
Is there anyway to stop page requests loading the data if another link is clicked and just deal with that link?
Further info - I am using a master page where the navigation menu is located and also ajax update panels on the home page.
回答1:
function cancelPostBack() {
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm.get_isInAsyncPostBack()) {
prm.abortPostBack();
}
}
Attach this function to the onclick event of the navigation item to ensure any pending requests are cancelled before navigation continues.
来源:https://stackoverflow.com/questions/14335389/cancel-requests-on-link-clicked-asp-net