More in this section

Forums / Developing with Sitefinity / Script tag not being written

Script tag not being written

8 posts, 0 answered
  1. Michael Risser
    Michael Risser avatar
    6 posts
    Registered:
    19 Nov 2009
    16 Dec 2009
    Link to this post
    Please let me start by saying I'm new to ASP.NET, I've been programming PHP for the last 11 yrs, so maybe I'm just missing some small nuance. That being said this may not be the right place to post this.

    The problem is I'm generating JavaScript and CSS tags behind the scenes and placing them in the head of the web page. Of the 6 script tags and 1 link tag that I'm generating, 5 script and 1 css tags are being generated, 1 script tag is not.

    Here is the code I'm using in my code behind file:
    1 protected void Page_Load(object sender, EventArgs e) 
    2     { 
    3         // Determine the document root 
    4         string RootPath = System.Web.VirtualPathUtility.ToAbsolute("~"); 
    5  
    6         // Add some JavaScript containing common paths for our theme 
    7         HtmlGenericControl jsPaths = new HtmlGenericControl("script"); 
    8         jsPaths.ID = "JavaScriptPaths"
    9         jsPaths.InnerHtml = "var root_path = \'" + RootPath + "\';\n" + 
    10             "var theme_path = root_path + \'/App_Themes/RSAR\';\n" + 
    11             "var css_path = theme_path + \'/css\';\n" + 
    12             "var img_path = theme_path + \'/images\';\n" + 
    13             "var js_path = theme_path + \'/javascript\';\n"
    14  
    15         // Add the jquery metadata plugin 
    16         HtmlGenericControl metadataJs = new HtmlGenericControl("script"); 
    17         metadataJs.ID = "MetaData"
    18         metadataJs.Attributes.Add("type""text/javascript"); 
    19         metadataJs.Attributes.Add("src", RootPath + "/App_Themes/RSAR/javascript/jquery.metadata.js"); 
    20  
    21         // Add the Fancybox plugin 
    22         HtmlGenericControl fancyboxJs = new HtmlGenericControl("script"); 
    23         fancyboxJs.ID = "FancyBoxJs"
    24         fancyboxJs.Attributes.Add("type""text/javascript"); 
    25         fancyboxJs.Attributes.Add("src", RootPath + "/App_Themes/RSAR/javascript/jquery.fancybox-1.2.6.js"); 
    26          
    27         HtmlGenericControl fancyboxCss = new HtmlGenericControl("link"); 
    28         fancyboxCss.ID = "FancyBoxCss"
    29         fancyboxCss.Attributes.Add("rel""stylesheet"); 
    30         fancyboxCss.Attributes.Add("type""text/css"); 
    31         fancyboxCss.Attributes.Add("href", RootPath + "/App_Themes/RSAR/css/jquery.fancybox-1.2.6.css"); 
    32          
    33         // Add the tablesorter plugin 
    34         HtmlGenericControl tablesorterJs = new HtmlGenericControl("script"); 
    35         tablesorterJs.ID = "TableSorter"
    36         tablesorterJs.Attributes.Add("type""text/javascript"); 
    37         tablesorterJs.Attributes.Add("src", RootPath + "/App_Themes/RSAR/javascript/jquery.tablesorter.min.js"); 
    38  
    39         // Add the common jquery functions 
    40         HtmlGenericControl commonJS = new HtmlGenericControl("script"); 
    41         commonJS.ID = "CommonScripts"
    42         commonJS.Attributes.Add("type""text/javascript"); 
    43         commonJS.Attributes.Add("src", RootPath + "/App_Themes/RSAR/javascript/jquery.common.js"); 
    44  
    45         // Add them all to the page header 
    46         Page.Header.Controls.Add(fancyboxCss); 
    47         Page.Header.Controls.Add(fancyboxJs); 
    48         Page.Header.Controls.Add(jsPaths); 
    49         Page.Header.Controls.Add(metadataJs); 
    50         Page.Header.Controls.Add(tablesorterJs); 
    51         Page.Header.Controls.Add(commonJS); 
    52     } 

    Lines 21-25 and 47 (fancyboxJS) seem to be where the problem is, this is the script tag that never makes it to the browser. Everything else is being generated and sent to the browser just fine, but that one script tag never makes it. I've been over the code many times but can't find anything wrong.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    16 Dec 2009
    Link to this post
    Hi Michael Risser,

    There seems to be no problem with the code that you are sending. Most pobably the path to the js file is not correct. I have tried adding the facybox plugin reference with your code (just changed the pat) and the script gets in the page header (my path is ~/Sitefinity/ExternalLibraries/fancybox/jquery.fancybox-1.2.6.js). See attached image for reference.

    You can try this as an alternative approach. The result will be the same
    //this is a control that will add jQuery script to page header
           JsFileLink jqueryLink = new JsFileLink();
           jqueryLink.ScriptType = JsFileLink.JavaScriptType.jQuery;
     
           JsFileLink fancyboxLink = new JsFileLink();
           fancyboxLink.ID = "fanxyboxLink";
           fancyboxLink.FileName = "~/Sitefinity/ExternalLibraries/fancybox/jquery.fancybox-1.2.6.js";
     
           CssFileLink fancyBoxCss = new CssFileLink();
           fancyBoxCss.FileName = "~/Sitefinity/ExternalLibraries/fancybox/jquery.fancybox-1.2.6.css";
     
           Page.Controls.Add(jqueryLink);
           Page.Controls.Add(fancyboxLink);
           Page.Controls.Add(fancyBoxCss);

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Michael Risser
    Michael Risser avatar
    6 posts
    Registered:
    19 Nov 2009
    16 Dec 2009
    Link to this post
    Hi Radsolov,

    Thanks for your quick reply.

    I've checked and rechecked the path and it is correct, the fancybox script is residing in the same directory as the other scripts, tablesorter, etc. I can put the path into my browser and it grabs the script, so I know that that is not the issue.

    But even if the path was wrong, would that prevent it from writing the script tag to the page?

    I wish I had known about JsFileLink, that would have saved me a lot of aggravation. I'll give JsFileLink a try and see if that helps.
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    16 Dec 2009
    Link to this post
    Hello Michael Risser,

    Thank you for getting back to me.

    When I think about it, if the path is wrong it will still write the script tag to the header, however this script tag will say that the file was not found. Please give the suggested way a try and get back to us with the results.

    Regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Michael Risser
    Michael Risser avatar
    6 posts
    Registered:
    19 Nov 2009
    16 Dec 2009
    Link to this post
    Well I gave that a try, but it didn't work, although it has given me another piece to the puzzle.

    I even went so far as to move the scripts into the Sitefinity/ExternalLibraries directory as you had them and changed the paths in the code accordingly, and I've discovered that the problem appears to be a caching issue, which I can't seem to get around. The tags are all being written with the old path (~/App_Themes/RSAR/) instead of the new one (~/Sitefinity/ExternalLibraries).

    I've tried recycling the App Pool, restarting IIS, "dummy" editing and saving both of the web.config files, deleting everything in the .NET Temp directory and even restarting my development machine. But the old paths are still being written to the tags. (And caching is turned off on the page)
  6. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    17 Dec 2009
    Link to this post
    Hello Michael Risser,

    How is the site set up? Are you trying to make changes on a live site, or just a local website running on localhost? What do you mean the both web.config files? Are is your site as a child application to another site. If you have the site on a live server did you first push the changes to the live site? If you are using custom controls, whose code is not in App_Code, make sure that you recompile the dlls and the website.

    Greetings,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Michael Risser
    Michael Risser avatar
    6 posts
    Registered:
    19 Nov 2009
    22 Dec 2009
    Link to this post
    I apologize for not having gotten back to you sooner, Its been busy around here.

    I'm making the changes on a local website running on localhost.

    When I refer to both web.config files, I mean the one in the site's root directory and the one in the Sitefinity directory.

    The site is a child of the default web site on the localhost, as setup by the telerik installer.

    I do not have any custom controls as yet, and I've tried re-building the entire website, but that hasn't helped either.
  8. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    23 Dec 2009
    Link to this post
    Hello Michael Risser,

    Thank you for getting back to me.

    The only web.config file that should be modified is the one in the root directory of your website. This is an interesting issue and I have not come across a similar one. Dummy editing the web.config in website root should restart the website is essentially the same as recycling the application pool. Since you do not have any custom controls I assume that you are adding this code in the page load event of your master page. Am I correct? Could you send us your whole master page and its code file, so that we can try it out on our side?

    Regards,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
8 posts, 0 answered