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

Where to place javascript?

1 Answer 161 Views
ScriptManager and StyleSheetManager
This is a migrated thread and some comments may be shown as answers.
STEVEN
Top achievements
Rank 1
STEVEN asked on 17 Jul 2011, 07:55 AM
Hi,

I have some confusion on the best practices to place the javascript in the page.
Whenever, i add a new webform via the 'Add RadControl Scenarios' from the Solution Explorer, 
it will generate this for me.

The question I have is where is the best place for me to place the javascript?
Right now, I place it after the //Put your JavaScript code here. 
However, after looking various examples in your demo and this, http://www.telerik.com/help/aspnet-ajax/ajax-radscriptblock-radcodeblock.html
I am not sure where is the best location to place my javascript. Please advise. <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> <Scripts> <%--Needed for JavaScript IntelliSense in VS2010--%> <%--For VS2008 replace RadScriptManager with ScriptManager--%> <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"> //Put your JavaScript code here.     function ShowRadWindowM() {         var wnd = $find("<%=RadWindow4.ClientID %>");         wnd.setUrl("radwindow_MinimizeZone.aspx");         wnd.show();         wnd.maximize();     }     </script>

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 18 Jul 2011, 01:24 PM
Hi Steven,

The best location for all the JavaScript code your pages will use is an external file, referenced in the <head> of the respective page. However, when working with RadControls for ASP.NET AJAX and using script code containing ASP.NET code-blocks ($find("<%=RadWindow4.ClientID %>");) the best way to put your code is after the (Rad)ScriptManager before the closing </body> tag.

I hope this helps.

Kind regards,
Simon
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
ScriptManager and StyleSheetManager
Asked by
STEVEN
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or