Archive for March, 2009

Mar 23 2009

ScriptManager vs ClientScript

Published by under .NET,General,Programming

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:

  1. Load base page.
  2. Start load of Application Status section.
  3. Start load of Risk section.
  4. 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:

    "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:

    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.

kick it on

One response so far

Mar 10 2009

The SharePoint Adrenalin Moment

Published by under Programming,Software

I’ve been developing with SharePoint for about 9 month now, and by developing I don’t mean airy-fairy SharePoint Designer drag-and-drop, I mean proper getting your hands dirty in code because SharePoint doesn’t have an *cough* out of the box *cough* feature that does what you want.

Mostly, deployment is done in two stages, firstly to a UAT box and then to a Live box.  Obviously the most efficient way to do this is to bundle your features into a solution which can easily be deployed onto any number of machines.  But, it does mean you have to make sure you’ve got everything right.  Untangling mistakes in your code can be a right royal pain in the arse.

By the time you’ve developed your solution, tested it out, deployed it to UAT and tested it again you should be fairly confident that when you come to deploy it on the Live server things should go pretty smoothly.  And, touch wood, to date things have gone smoothly.

But I still can’t get over that rush of adrenaline that comes with clicking “Activate Feature” after deploying the solution on Live.  In the second or two whilst the page waits to reload my mind runs through all the possible things that could go wrong and how long it would take me to unpick the changes my code might have got half way though.  Then the page finally loads…..

….. “Feature Activated”, phew!  Time for a lie down to clam my nerves.

2 responses so far

Mar 06 2009

Detecting Document Loaded on Window.Open()

Published by under General

One of the tasks I have to achieve in a CRM project I’m working on requires opening a new IE window and identifying when the document within it has been loaded.

Unfortunately I have been unable to find a solution to this online but  found plenty of references to methods that don’t work.  So I decided to play around until I found a method that work and blog about it…. I guess I succeeded as you’re reading this!

Creating a new window using JavaScript is easy enough:

<script language="javascript">
    var newWindow ="popup.html", "new popup window");

What would be really useful is if you could attach to an onload event of the newWindow variable.  Unfortunately this isn’t possible.  What I have found out is that it is possible to call back from the popup window to the code that loaded it.

For example, if we have two pages index.html and popup.html we can add the following code to index.html:

<script language="javascript">"popup.html", "new popup window");
    function popupLoaded(newWindow)
        // code to run after popup has loaded

Within popup.html we can then added the following which will call back to the popupLoaded function in index.html when the popup is loaded:

<script language="javascript">
    function callback() {    
<body onload=?callback()?>

The reason for the inclusion of the newWindow parameter of popupLoaded is to be able to get a handle on the new popup window.  I tried using a object returned from but it didn’t seem to keep a valid handle to the popup window.

kick it on

2 responses so far