Mar 23 2009
As part of a Microsoft Dynamics CRM customisation project, I was recently tasked with modifying an ISV add-in page so that individual sections of the page could be refreshed without having to refresh the entire page.
That in itself was nice and easy, it just required the use of a couple of UpdatePanel and UpdateProgress controls to be dropped on the page along with a ScriptManager control to handle the partial postback requests.
However, there were a couple of gotchas that I didn’t foresee. Along with the partial updates, the client wanted the parts of the page to load the first time after the page had first loaded in the following order:
- Load base page.
- Start load of Application Status section.
- Start load of Risk section.
- Start load of Alerts section.
Unfortunately, the ScriptManager that comes with ASP.Net AJAX only handles one postback at a time. Any subsequent postbacks take precedence over earlier request, which is fine if you only have one update panel on a page but this initially resulted in only the Alerts section being loaded – the other postbacks being canceled.
Luckily I found a very useful post on Amit’s Blog: Asp.Net Ajax UpdatePanel Simultaneous Update. This post provides code that queues postback requests. Ideally I would have liked to have the requests happening at the same time, but this is the next best thing.
The other problem that I found was that one of the sections on the page had previously been dynamically creating and reqistering script that got loaded and executed when the page loaded using:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ShowNavBarItem", script.ToString());
Unfortunately that doesn’t work with the AJAX ScriptManager. Instead I had to change the code to use the ScriptManager to load and execute the code using the following:
ScriptManager.RegisterClientScriptBlock(updatePanelApplications, typeof(UpdatePanel), "showNavBarItems", script.ToString(), true);
This means that each time the section is updated I can re-generate the script and it will be executed again.
With this AJAX loading and some enhancements to the SQL code, users now get a much fasted load and response time for the page as the no longer have to wait for the whole page to be rendered before seeing information appearing on the page.