Control Cannot Find JavaScript File

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/19/2012 11:03:48 AM
Gravatar
Total Posts 148

Control Cannot Find JavaScript File

I built a User Control that uses some JavaScript.  I created a .js file and place it in the same directory as my control.

I place my control in the layout.Master under my skins folder.

I put the full path to my .js file in the control like this:

<script type="text/javascript" src="~/MyControls/MyjavaScriptFile.js"></script>

The control cannot find the javascript file.

3/19/2012 11:12:01 AM
Gravatar
Total Posts 42

Re: Control Cannot Find JavaScript File

Hi,

try to remove "~" from the path.

Try:

<script type="text/javascript" src="/MyControls/MyjavaScriptFile.js"></script>

or

<script type="text/javascript" src="./MyControls/MyjavaScriptFile.js"></script>

Tomasz

3/19/2012 11:33:03 AM
Gravatar
Total Posts 148

Re: Control Cannot Find JavaScript File

Thanks.

The

<script><type="text/javascript" src="/MyControls/MyJavaScriptFile.js"></script>

worked.

I'm confused when to use:

"~/MyControls/MyJavaScriptFile.js"

"../MyJavaScriptFile.js"

"/MyControls/MyJavaScriptFile.js"

Is there a quick and easy rule to remember?

3/20/2012 8:44:07 AM
Gravatar
Total Posts 18439

Re: Control Cannot Find JavaScript File

~/ is only for server side code like .NET controls can have that assigned for an url like on <asp:Hyperlink NavigateUrl="~/whatever.aspx"

it cannot be used in raw html, but in some cases you can use it with raw html like this:

<a href='<%= Page.ResolveUrl("~/whatever.aspx")%>'>My Link</a>

The advantage of ~/ is that it can resolve the applicaiton root correctly no matter if the site is a root level site or running in a sub folder/virtual directory whereas the html way / always resolves to the root of the web site not the virtual directory.

Usually I don't add script the way you did, I add it from code as in the article Adding Custom Javascript.

Hope that helps,

Joe

You must sign in to post in the forums. This thread is closed to new posts.