Cancel Requests on link clicked asp.net

谁说胖子不能爱 提交于 2020-01-06 07:59:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!