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

Using external .js files

2 Answers 87 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
pirobox
Top achievements
Rank 1
pirobox asked on 05 Aug 2010, 10:48 AM
Hi,
   sorry for bothering you, but this is getting me crazy.
I'm using 2010q2.

The problem:

What I'm trying to accomplish is to use external js files instead of the "axd" resource files.
I've looked to your examples and I don't find them suitable for an application of medium/large dimension.
In fact you are suggesting of adding the scripts to the ScriptManager
<asp:ScriptManager ID="ScriptManager1" runat="server" >
      
<Scripts>
         
<asp:ScriptReference Path="~/Scripts/Common/Core.js" />

      </Scripts>
</
asp:ScriptManager>


This is a mess when dealing with hundreds of pages because developers must always remember which js files must be included for each control.

My idea (as a sidenote I've always used this approach with all the third party libraries I've used in all my projects):
I inherited from your controls, for example I created
public class ExTabStrip : RadTabStrip
(another sidenote: I plan to do it independently of this issue, because it is always better to be able to add new behaviors to third party controls)
Since I know a bit of asp.net I've looked to your controls and noticed that they are implementing MS IScriptControl interface, so I thought the right solution was to override
IEnumerable<ScriptReference> GetScriptReferences()
and add there the external js files. In this way everything is wrapped in the control and the page must not know about these details.
For example 
protected override IEnumerable<ScriptReference> GetScriptReferences()
{
List<ScriptReference> scriptReferences = new List<ScriptReference>();
scriptReferences.Add(new ScriptReference("~/JS/Telerik/Common/Core.js"));
... // Other js files specific for each control
return scriptReferences;
}
But I get a lot of js errors. Sometimes this happens because some js files are imported more than once in the page (like the "PopupScripts.js" script)

Is this approach correct?
Is there any way to reach my goal?

Best regards, Andrea Pirola

2 Answers, 1 is accepted

Sort by
0
pirobox
Top achievements
Rank 1
answered on 09 Aug 2010, 07:31 AM
Hi,
since I've made progresses I share them.
In order to be able to register telerik js files in my controls I add to use this patters (example for Core.js):
new ScriptReference("~/JS/Telerik/Common/Core.js"){Assembly = "Telerik.Web.UI", Name = "Telerik.Web.UI.Common.Core.js", Path = "~/[TELERIKJSFOLDER]/Common/Core.js"}
Setting the assembly and the name seems to solve all the problems I had (at runtime I often received twice the same file).

I was also able to subclass Telerik controls client side. This is the pattern I followed (Example for a subclass of the RadTabStrip)
protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
{
List<ScriptDescriptor> descriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
ScriptControlDescriptor scriptControlDescriptor = (ScriptControlDescriptor)descriptors[0];
scriptControlDescriptor.Type = "DX.Ctrl.FxTabStrip";
return descriptors;
}
I simply override the GetScriptDescriptors method and change the name of the class that must be instantiated for a tabstrip (Obviously I've create a js class named "DX.Ctrl.FxTabStrip" that inherits from "Telerik.Web.UI.RadTabStrip" js component).

Best regards, Andrea Pirola

0
Peter
Telerik team
answered on 10 Aug 2010, 09:56 AM
Hi Andrea,

Thank you for sharing your findings. We are glad that you were able to solve the problem yourself and apologize that we could not help you right away.

Don't hesitate to contact us if you have other questions.

Kind regards,
Peter
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
Tags
General Discussions
Asked by
pirobox
Top achievements
Rank 1
Answers by
pirobox
Top achievements
Rank 1
Peter
Telerik team
Share this question
or