I am going to make some assumptions about what you are trying to fulfill. Most likely you have a javascript file that needs access to some information on the server. Let's say you need something from the session, that if it were an aspx page, you would look something like this:
<script type="text/javascript"> var username = '<%= Session["username"] %>'; var account_num = '<%= Session["account_num"] %>'; </script>
obviously this will not work in the .js file since it never goes through the life cycle of the page, which will be treated as an aspx page. However, you do not need to convert your entire .js file to an .aspx page, as some may suggest. There are many other ways to provide this data to your js code. I will list 2.
- fix the above
<script> in the response to your page (possibly using <asp:ContentPlaceHolder /> ) - create a web service (maybe even a simple .ashx) that returns
var username = ... or even better returns json
source share