0

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.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
ian_mac123
  • 107
  • 1
  • 2
  • 14

1 Answers1

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.

Justin L.
  • 993
  • 14
  • 33
James
  • 926
  • 1
  • 8
  • 24
  • Thanks for that, I know I am being a little thick here but how would I get the Javascript into the navigationmenu onclick event when the NavigationMenu_MenuItemClick event is taken up by some c# code on the master page? – ian_mac123 Jan 15 '13 at 10:37
  • This page here http://stackoverflow.com/questions/9928488/jquery-click-method-on-asp-net-menu-item offers suggestions on how you can go about doing this, the client side function will fire first before firing the server side event. – James Jan 15 '13 at 20:39