How to include Javascript file in Asp.Net page

Vaibhav Jain picture Vaibhav Jain · Nov 3, 2009 · Viewed 154k times · Source

I want to do some client side validation using javascript in ASP.NET page.

I tried using

<script src="../../../JS/Registration.js" language="javascript" type="text/javascript" />

but its not working. Please help.

Answer

o.k.w picture o.k.w · Nov 3, 2009

If your page is deeply pathed or might move around and your JS script is at "~/JS/Registration.js" of your web folder, you can try the following:

<script src='<%=ResolveClientUrl("~/JS/Registration.js") %>' 
type="text/javascript"></script>