Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 4 of 4

Thread: including scripts

  1. #1
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default including scripts

    I have the following javascript scripts that I need to include in the head of my page. I have put this in template.master and it works fine until I go to a product that is in /product/1/product.aspx.
    Code:
    <script type="text/javascript" src="jscripts/jquery.min.js"></script>
    <script type="text/javascript" src="jscripts/jquery.hoverIntent.minified.js"></script>
    <script type="text/javascript" src="jscripts/menu.js"></script>
    I tried doing runat=server in the script tag but that didn't work. Ideas?

  2. #2
    Richnyc30 is offline Senior Member
    Join Date
    Mar 2009
    Posts
    340

    Default scripts

    I, too, would like to knw more about using scripts. I understand scripts.

  3. #3
    valentim is offline Senior Member
    Join Date
    Apr 2006
    Posts
    192

    Default

    Changing your include to contain a leading slash should fix your issue:

    <script type="text/javascript" src="/jscripts/jquery.min.js"></script>
    Matthew
    Aydus Consulting
    Strategy+Development+Design=The Aydus Difference

  4. #4
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    Actually putting a leading / in the script SRC is a bad idea. If your site isn't hosted at the root level then it will break every time. Instead you should either load the script in to the ScriptManager or should specify the site-root variable.

    To turn on the ScriptManager:
    Code:
    Public Overrides ReadOnly Property RequireScriptManager() As Boolean
    	Get
    		Return True
    	End Get
    End Property
    To add to the ScriptManager:
    Code:
    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    	DirectCast(Master.FindControl("scrptMgr"), ScriptManager).Scripts.Add(New ScriptReference("/jscripts/SafariChromeAJAXFix.js"))
    End Sub
    *Note: there is no ~ before the leading / because this is talking about the path the compiler follows.

    Or

    Code:
    <script type="text/javascript" src="~/jscripts/jquery.min.js"></script>
    *Note the ~ before the leading /. That is what tells ASP.Net to start from the site root, not the domain root.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM