Cannot use an UpdatePanel in a SharePoint 2010 Sandbox Solution

Cannot use an UpdatePanel in a SharePoint 2010 Sandbox Solution

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 Smile

5 thoughts on “Cannot use an UpdatePanel in a SharePoint 2010 Sandbox Solution

  1. Wictor Wilén

    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.

    1. Alex

      Hi Wictor,

      Thanks for the reply it’s great to have a solid answer for the reason why you cannot get a reference to the ScriptManager. I will update the post to include your comment.

      Cheers

      Alex

  2. Amy Grossman

    Well that explains a lot. :-) So…what do people usually do to get around this issue? My current stumbling block is that I have a SharePoint 2010 page that I want to use an Ajax update panel in a reusable custom web part. This is so that we can use it on an internal farm and an external farm. It worked okay if I published as a custom control, but not when I tried re-using it on the second farm.

  3. Bernhard

    I tried to setup a Sandboxed Webpart on SP 2013. In fact I was able to create the webpart and at least I was able to add an ScriptManager inside the webpart without throwing an error. But unfortenatly it didn’t work. I always got a full page reload.

    Getting help in msdn-Forum I was explained that updatepanel doesn’t work in Sandboxed Solutions…
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/2b7459b2-844b-4368-bfe6-8f62ce4e0285/using-updatepanel-in-sharepoint-2013-web-part

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">