Script References not loaded in Partial PostBack when specified as "new ScriptReference(resourceName,assemblyName)"

This appears to be an issue with SharePoint 2010 and I was finally able to dig up some information on this post.

This is a known issue in Sharepoint 2010. The script resources are not loaded if the controls are not visible initially ..

.. The “Sharepoint 2010 not emitting javascript links on partial postback” problem .. occurs, if controls are added (OR made visible) during a partial postback.

Thankfully,

Microsoft has finally addressed this issue as well in one of the Sharepoint 2010 cumulative updates for October 2011. Installing this update should generally fix the problems with hidden ajax controls registering their scripts.

It appears SharePoint Server 2010 cumulative update package (SharePoint server-package): October 25, 2011 is the first CU with the fix – although I have not verified this.


For historical reference – or for poor people like me who can’t ensure that the CU/SP applied – a “work-about” is to manually register the resources. (This was also found in the linked post.)

public class MyComboBox : RadComboBox
{
    protected override System.Collections.Generic.IEnumerable<System.Web.UI.ScriptReference> GetScriptReferences()
    {
#if MANUAL_SCRIPT_POSTBACK_FIX
        HashSet<string> registeredNames = new HashSet<string>();
        ReadOnlyCollection<RegisteredScript> registeredScripts = ScriptManager.GetCurrent(Page).GetRegisteredClientScriptBlocks();           
        foreach (RegisteredScript registeredScript in registeredScripts)
        {
            registeredNames.Add(registeredScript.Key);
        }
         
        foreach (ScriptReference reference in base.GetScriptReferences())
        {
            if (!registeredNames.Contains(reference.Name))
            {
                ScriptManager.RegisterClientScriptResource(this, typeof(MyComboBox).BaseType, reference.Name);
            }
        }
        return new List<ScriptReference>();
#else
        return base.GetScriptReferences();
#endif     
    }
}

Browse More Popular Posts

Leave a Comment