0

I have validation.js in scripts folder of my .net project. I am using asp:content pages which has master page. I have referenced the .js file in master page and used it in one of the asp:content web page but it does not work. I have also tried to reference it directly to the asp:content web page but it still does not work however when I copy the js code directly to the asp:content page of header section it works. I have tried several things such as

<script src='<%= Page.ResolveClientUrl("../Scripts/js/validation.js") %>' type="text/javascript"></script>

I have also tried:

<script type="text/javascript" src="Scripts/js/validation.js"></script>

What am I missing.

In my asp:content page I have textboxes such as

Please help me here

2
  • Try Remove the ../ and add ~/ i.e <script src='<%= Page.ResolveClientUrl("~/Scripts/js/validation.js") %>' type="text/javascript"></script> Commented Dec 22, 2014 at 5:06
  • Why are you using 'Page.ResolveClientUrl' here? Commented Dec 22, 2014 at 5:07

3 Answers 3

2

Simply drag the js file and drop it on master page it will automatically add js file with correct path.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm I didn't know that nice !
0

You could use a ScriptManager for referencing your JS file like

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="../Scripts/js/validation.js" />
    </Scripts>
</asp:ScriptManager>

If you want JS to be referenced in your Header section only you may use

<head>
    <script type="text/javascript" 
        src="<%= Page.ResolveClientUrl("~/Scripts/js/validation.js") %>"></script>
</head>

Comments

0

Drag and drop the you JS file after the body closing tag :

Sample;

</body>
<script src="../Scripts/js/validation.js" type="text/javascript"></script>
</html>

Hope it helps!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.