Where to place javascript?

2 posts, 0 answers
    STEVEN avatar
    37 posts
    Member since:
    Oct 2010

    Posted 17 Jul 2011 Link to this post

    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>
  2. Simon
    Simon avatar
    2281 posts

    Posted 18 Jul 2011 Link to this post

    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,
    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!

Back to Top