I recently worked on some AJAX web parts for SharePoint where we decided to add the ScriptManager to the page programmatically. I was simply looking for an existing instance of the ScriptManager on the page and if one was not found, I was adding the ScriptManager to the Controls collection of the web part. Then I’ve spend the rest of the week trying to figure out why this doesn’t always work. While digging around the web, I ended up at the SharePoint Team Blog to a post about ASP.NET AJAX Support in WSS 3.0 SP1. I was not surprised to read that the ScriptManager should be added directly to the page or master page rather attempting to load it programmatically through your web part. This is simply because the ScriptManager needs to be the very first control on the page and that was not guaranteed inside a web part since other controls will be added first if your web part doesn’t load first. So if you are attempting something similar, just add a ScriptManager to your master page’s markup.

Advertisements