This is a migrated thread and some comments may be shown as answers.

Hidden ajax radcontrols not registering scripts in sharepoint

8 Answers 95 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gilbert
Top achievements
Rank 1
Gilbert asked on 06 Apr 2011, 04:11 PM
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

8 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 06 Apr 2011, 07:24 PM
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
0
Gilbert
Top achievements
Rank 1
answered on 06 Apr 2011, 08:09 PM
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
0
Marin
Telerik team
answered on 08 Apr 2011, 09:51 AM
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
0
leitel
Top achievements
Rank 1
answered on 22 Apr 2012, 06:37 PM
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

0
Marin
Telerik team
answered on 23 Apr 2012, 08:04 AM
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.
0
leitel
Top achievements
Rank 1
answered on 23 Apr 2012, 09:39 AM
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
0
Marin
Telerik team
answered on 23 Apr 2012, 09:51 AM
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.
0
leitel
Top achievements
Rank 1
answered on 23 Apr 2012, 10:34 AM
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
Tags
General Discussions
Asked by
Gilbert
Top achievements
Rank 1
Answers by
Marin
Telerik team
Gilbert
Top achievements
Rank 1
leitel
Top achievements
Rank 1
Share this question
or