akvickyit7
akvickyit7

Reputation: 225

Masterpage js/code not working in subfolders

I have a dialog in the master HTML and I'm hiding it and showing it based on a button, which is also in the master HTML. Everything hides/shows fine in root pages but not on pages in subfolders. When these are displayed the dialog HTML code is never hidden and the button click doesn't do anything. The Script in my master page is like this:

<script type="text/javascript">
    $(document).ready(function () {
        $('#Id_GL').click(function () {
            $('#div_GL').show();
            $('#div_AP').hide();
            $('#div_AR').hide();
        });           
    });
    </script>

Is there any way to get my master page to behave with subfoldered pages? i call the javascript in master page like this

 <script src="js/jquery/jquery.min.js"></script>
<script src="js/jquery/jquery.widget.min.js"></script>
<script src="js/jquery/jquery.mousewheel.js"></script>
<script src="js/prettify/prettify.js"></script>

<!-- Metro UI CSS JavaScript plugins -->
<script src="js/load-metro.js"></script>

<!-- Local JavaScript -->
<script src="js/docs.js"></script>
<script src="js/github.info.js"></script>

Upvotes: 0

Views: 1987

Answers (2)

IrishChieftain
IrishChieftain

Reputation: 15253

I've experienced this problem with master pages in every edition of VS that I have used. The only way I ever get script or CSS paths to resolve is to drag them from Solution Explorer into the code view of the master page. Trying to resolve it with "~" didn't work either.

Upvotes: 0

frikinside
frikinside

Reputation: 1244

Those JavaScript includes refers to a relative path. When you are in a subfolder, the relative path leads to a non existing file. You need to use a resolving path. You can do that with ~/ or with ResolveUrl("~").

Using your includes could be something like this:

<script src="<%= ResolveUrl("~") %>js/jquery/jquery.min.js"></script>
<script src="<%= ResolveUrl("~") %>js/jquery/jquery.widget.min.js"></script>
<script src="<%= ResolveUrl("~") %>js/jquery/jquery.mousewheel.js"></script>
<script src="<%= ResolveUrl("~") %>js/prettify/prettify.js"></script>

<!-- Metro UI CSS JavaScript plugins -->
<script src="~/js/load-metro.js"></script>

<!-- Local JavaScript -->
<script src="~/js/docs.js"></script>
<script src="~/js/github.info.js"></script>

I mix the two methods so you could see the difference.

Upvotes: 2

Related Questions