I have been working on a SharePoint 2010 web part recently that uses an EditorPart to allow the users to set some properties for the web part.
I wanted to use an UpdatePanel within the EditorPart to avoid postbacks and as I understood it the SharePoint 2010 masterpages already have a ScriptManager in them.
Sadly it seems this is not possible – if you try to add an UpdatePanel within the CreateChildControls method you will get an exception – ‘The control with ID UpdatePanel1 request a ScriptManager on the page’. This indicates that you need to add a ScriptManager to the page which is strange as the masterpage should already contain one!
If you try to add a ScriptManager to your web part you will get a InvalidOperationException– ‘The PageRequestManager cannot be initialized more than once’. This indicates that a ScriptManager already exists on the page – which is correct as the masterpage contains one.
Unfortunately you are not able to get a reference to this ScriptManager as ScriptManager.GetCurrent() returns null.
I created the same web part as a farm solution and low and behold I am able to add an UpdatePanel straight away with no problems and ScriptManager.GetCurrent() returns the ScriptManager!
*Update – Wictor has commented on this post describing why you can’t get a reference to the ScriptManager object in the sandbox:
Hi, this is not a bug. It’s a feature of the Sandbox. The SB creates its own copy of the Page object and “copies” some information from the real Page object to the SB page object – but not everything such as the ScriptMgr reference etc.
Hope this helps