Hidden ajax radcontrols not registering scripts in sharepoint

9 posts, 0 answers
  1. Gilbert
    Gilbert avatar
    16 posts
    Member since:
    Jun 2009

    Posted 06 Apr 2011 Link to this post

    Hi,

    In my project I am creating normal ASP .NET user controls, then wrap them up as Sharepoint (using 2010) web parts for deployment. Everything works fine in Sharepoint if there is an instance of the Rad Control already visible on the page. However, sometimes I only have one instance of the control in the page and it starts out Visible = false. When I trigger an event to show the control I get things that no longer work. For example, RadNumericTextbox will throw a javascript error, RadDatePicker and RadTimerPicker will no longer popup the picker if I click on the icon. This looks like it's because the script resource for the controls aren't loaded initially because they are hidden. If I use styles and set "display: none" then it's fine, Creating hidden controls in the master page would work but it would be better if there was something I can set, perhaps in the RadScriptManager, to do this.

    Thanks,
    Gilbert
  2. Marin
    Admin
    Marin avatar
    1057 posts

    Posted 06 Apr 2011 Link to this post

    Hello Gilbert,

    Indeed you are right. This is a known issue in Sharepoint 2010. The script resources are not loaded if the controls are not visible initially. One workaround available for now would be to add the appropriate javascript files for the controls manually through the RadScriptManager. Please refer to the following help topic for detailed explanation on how to do this.

    All the best,
    Marin
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Gilbert
    Gilbert avatar
    16 posts
    Member since:
    Jun 2009

    Posted 06 Apr 2011 Link to this post

    Hi Marin,

    Thanks for the response. Manually registering them does work. I guess I'll have to register all the scripts for the Rad Controls that I need to be using? I manage to find a similar thread after seeing your reply.

    http://www.telerik.com/community/forums/aspnet-ajax/general-discussions/sharepoint-2010-ajax-with-detailsview.aspx

    Since I'm using RadDatePicker as well is there plans to include Telerik.Web.UI.Calendar.RadPickersPopupDirectionEnumeration.js into the assembly?

    Thanks,
    Gilbert
  4. Marin
    Admin
    Marin avatar
    1057 posts

    Posted 08 Apr 2011 Link to this post

    Hello Gilbert,

    Yes, you need to register the scripts for all the controls that you are using on the current page.
    The referenced script should be present in the telerik assembly, you need to add it when using RadDatePicker.

    Greetings,
    Marin
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. leitel
    leitel avatar
    4 posts
    Member since:
    Jul 2007

    Posted 22 Apr 2012 Link to this post

    Hi
    even though this is a pretty old post, I want to share some workaround I found that is related to the "Sharepoint 2010 not emitting javascript links on partial postback" problem (or as you call it: "Hidden ajax radcontrols not registering scripts in sharepoint"). In general the problem occurs, if controls are added (OR made visible) during a partial postback.

    The solution is to override GetScriptRefererence and add all Telerik scripts manually instead of letting the ScriptManager
    do the work (see the example for a RadComboBox):

        
    public class MyComboBox : RadComboBox {
        protected override System.Collections.Generic.IEnumerable<System.Web.UI.ScriptReference> GetScriptReferences()
      {
      IEnumerable<ScriptReference> baseReference = base.GetScriptReferences();
      foreach (ScriptReference reference in baseReference)
      {
        ScriptManager.RegisterClientScriptResource(this, this.GetType().BaseType, reference.Name);
      }
      return new List<ScriptReference>();           
      }
    }


    This might be not the best solution, however it works, i.e. ScriptReferences added this way will be rendered in a partial post back scenarios as well.
    If you add the scripts manually, you don't let the ScriptManager (or the ScriptManagers "OnResolveScriptReference" handler respectively, ...just a hint), decide what scripts to include and what scripts to ignore.

    Kind regards, Andreas

  6. Marin
    Admin
    Marin avatar
    1057 posts

    Posted 23 Apr 2012 Link to this post

    Hello Andreas,

     Thank you very much for sharing this solution. It is really a nice workaround.

    Also I am happy to inform you that 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. 

    Greetings,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. leitel
    leitel avatar
    4 posts
    Member since:
    Jul 2007

    Posted 23 Apr 2012 Link to this post

    Hello Marin
    thank you for the reply. Do you have an idea of the exact Microsoft KB Issue that addresses this problem?
    Kind regards, Andreas
  8. Marin
    Admin
    Marin avatar
    1057 posts

    Posted 23 Apr 2012 Link to this post

    Hello,

     I think it should be this one:
    http://support.microsoft.com/kb/2596505 

    Regards,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. leitel
    leitel avatar
    4 posts
    Member since:
    Jul 2007

    Posted 23 Apr 2012 Link to this post

    Hi Marin, once again, thank you.
    However, for the reason of completeness, I would like to provide you with a better solution that also makes sure, ScriptReferences are only added to the list of client script resources once. It is important to make sure, that these scripts are not added multiple times since otherwise the script loading may fail at the client side (due to multiple javascript calls to:

    if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();



    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
     
            }
        }


    You can control the behaviour with the compiler symbol MANUAL_SCRIPT_POSTBACK_FIX
    Again, not an optimal solution, but its working.
    Kind regards, Andreas
Back to Top