Cancel Requests on link clicked asp.net

2019-09-12 16:13发布

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条回答
姐就是有狂的资本
2楼-- · 2019-09-12 17:17
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.

查看更多
登录 后发表回答