Asp.net page location issue

I am creating a usercontrol. This control uses javascript
<script src='js/my.js' type='text/javascript'></script>

Location of my web directory here ->

App_code\myusercontrol.css
User\aa.aspx
bb.aspx

      

aa.aspx

And bb.aspx

my created user control is used. My problem:
when I call aa.aspx

, work successfully
when I call bb.aspx

, javascript location error

I change the script to <script src='../js/my.js' type='text/javascript'></script>


when I call bb.aspx

, work successfully
when I call aa.aspx

, javascript location error

How to solve this problem?

+2


source to share


1 answer


You can give the absolute path to your script IE:

<script src='/js/my.js' type='text/javascript'></script>



Or you can dynamically resolve the url via asp ...

<script src='<%=ResolveUrl("~/js/my.js")%>' type='text/javascript'></script>

      

+6


source







All Articles