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

Adding scripts with RadScriptManager

3 Answers 1126 Views
ScriptManager and StyleSheetManager
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 17 May 2012, 12:07 PM
Hi, I’m updating an ASP.NET AJAX application so that the jQuery library loaded by the Telerik.Web.UI assembly can be re-used by other scripts. I have two questions which I’d appreciate some advice on:

I have a RadScriptManager on my master page and need to include a private javascript file that can be used by all content pages. Should I include the script as a reference within the RadScriptManager or should I use conventional script tags after the RadScriptManager? I’ve illustrated both methods below. Both seem to work but what is the recommended approach?

METHOD 1
<telerik:RadScriptManager ID="rsmMain" runat="server" >
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
</Scripts>
</telerik:RadScriptManager>
<script type="text/javascript" src="../Scripts/Utility.js"></script>

METHOD 2
<telerik:RadScriptManager ID="rsmMain" runat="server" >
<Scripts>
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
<asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
<asp:ScriptReference Path="~/Scripts/Utility.js" />
</Scripts>
</telerik:RadScriptManager>

My second question relates to adding a client-side script from a page programmatically. Previously I used the RegisterStartupScript() method of ClientScriptManager to add a script from code behind but I note from some forum posts that it’s suggested you should use RadScriptManager.RegisterStartupScript() instead. What’s the difference and is there a recommended approach?

Regards, Ian

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 21 May 2012, 04:28 PM
Hi Ian,

With respect to your first question: it doesn't really matter how you register the scripts. You may chose whatever approach you like better.

Regarding the second question, RegisterStartupScript on the script manager, it registers a startup script block for a control that is inside an UpdatePanel by using the ScriptManager control, and adds the script block to the page. In contrast, ClientScript.RegisterStartupScripts register a startup scripts with the page, it does not work with Ajax.

Kind regards,
Genady Sergeev
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
Ian
Top achievements
Rank 1
answered on 21 May 2012, 05:23 PM
Hi Genady,
Thanks for the explanation - it sounds like I should be using RadScriptManager.RegisterStartupScript() to register my script now.

One final question. When I previously used the ClientScriptManager method, there was a IsStartupScriptRegistered() method you needed to test to ensure the script [you wanted to add] wasn't already registered. There doesn't appear to be any equivalent with RadScriptManager. Does that mean RadScriptManager does this check internally?

Best regards, Ian 
 
0
Genady Sergeev
Telerik team
answered on 24 May 2012, 02:50 PM
Hi Ian,

RadScriptManager.RegisterStarupScript is simply inherited from the ASPNET ScriptManager. I've looked at he ScriptManager source code and noticed that it simply uses ClientScript.RegisterStartupScript in order to register the script, however, it does not perform check whether the script is already registered. You should be able to use ClientScript.IsStartupScriptRegistered to check that.

Regards,
Genady Sergeev
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.
Tags
ScriptManager and StyleSheetManager
Asked by
Ian
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Ian
Top achievements
Rank 1
Share this question
or