More in this section

Forums / Developing with Sitefinity / javascript in masterpage

javascript in masterpage

8 posts, 0 answered
  1. Dino
    Dino avatar
    21 posts
    Registered:
    13 Jan 2008
    20 Nov 2008
    Link to this post
    Hi

    I'm doing the porting from exsisting asp.net website where in a masterpage is used this javascript library: modalbox.js
    The file in the masterpage are :
    <head>
    <script type="text/javascript" src="includes/prototype.js"></script>
    <script type="text/javascript" src="includes/scriptaculous.js?load=effects"></script>
    <script type="text/javascript" src="includes/modalbox.js"></script>
    </head>

    I tried do the same stuff in a sifinity masterpage but the script not working.
    Any idea?
    How can I use javascript library in sitefinity ?

  2. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    20 Nov 2008
    Link to this post
    Hello Dino,

    In order to use external Javascript files in the master page set out of the <HTML></HTML>:

    <script type="text/javascript" src='<% =this.Page.ResolveUrl("~/App_Master/JS_Call/script.js")%>'></script> 

    this will add script.js file which is contained in "App_Master\JS_Call" folder. I hope this helps.

    Greetings,
    Nikolay
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Dino
    Dino avatar
    21 posts
    Registered:
    13 Jan 2008
    20 Nov 2008
    Link to this post
    Hi
    yes this works.. but only if I put in the body and not in head tag.
    If I put in <head> I receive this:

     

    Server Error in '/' Application.

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
       System.Web.UI.ControlCollection.Add(Control child) +8667471
       System.Web.UI.PageTheme.SetStyleSheet() +478
       System.Web.UI.Page.OnInit(EventArgs e) +8688380
       Telerik.Cms.Web.CmsPageBase.OnInit(EventArgs e) +100
       System.Web.UI.Control.InitRecursive(Control namingContainer) +333
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378
    
  4. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    20 Nov 2008
    Link to this post
    Hello Dino,

    I wrote out of the <HTML> </HTML> tags like this:

    <%@ Master Language="C#" %> 
     
    <script type="text/javascript" src='<% =this.Page.ResolveUrl("~/App_Master/JS_Call/js.js")%>'></script> 
     
     
    <HTML xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server"
     
    .... 
     
    </HTML> 

    Sorry if I was not clear enough.

    All the best,
    Nikolay
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Dino
    Dino avatar
    21 posts
    Registered:
    13 Jan 2008
    20 Nov 2008
    Link to this post
    sorry ;-)
  6. MB
    MB avatar
    302 posts
    Registered:
    09 Jan 2005
    28 Nov 2008
    Link to this post
    Personally, I find that the best solution for Sitefinity Masterpages and script files is the ScriptManager... and I choose to use the Telerik version of it.

    <telerik:RadScriptManager id="MyScriptManager" runat="server">  
        <Scripts> 
            <asp:ScriptReference name="" Assembly="" Path="~/path/file1.js"></asp:ScriptReference> 
            <asp:ScriptReference name="" Assembly="" Path="~/path/file2.js"></asp:ScriptReference> 
        </Scripts> 
    </telerik:RadScriptManager> 

    -- MB.
  7. Dino
    Dino avatar
    21 posts
    Registered:
    13 Jan 2008
    28 Nov 2008
    Link to this post
    thanks.. good to know
  8. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    28 Nov 2008
    Link to this post
    Hello Mike,

    Yes, we somehow forget to suggest this way. Thank you for pointing this solution out!
    We just updated your Telerik points for a valuable reply!

    Sincerely yours,
    Georgi
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Register for webinar
8 posts, 0 answered