I have an ASP.NET web-app that consists of a master page and several .aspx pages that use that master page.
1. problem:
If I include the jQuery library in the master page at the bottom right before </body> (and after the content placeholder), then in my .aspx pages I am unable to use jQuery because it is included "below" all JS code defined in the pages.
Master page:
<!DOCTYPE html>
<html>
<head>
...
< ASP.NET head placeholder >
...
</head>
<body>
...
< ASP.NET body placeholder >
...
<script src="jquery.js"></script>
</body>
</html>
Regular .aspx page that uses the master page:
< head placeholder > ... </head placeholder>
<body placeholder>
... code for that particular page ...
<script>
... JS code for that particular page ...
</script>
</ body placeholder >
The only solution for this problem (that I can think of), is to include the jQuery library in the HEAD of the master page...
2. problem:
At first I was placing the document.ready() code for each .aspx page at the bottom of the page =
inline.
Like this...
<script>
$(document).ready(function()
...
});
</script>
However, I thought maybe it's better to place all JS code into one or more external files, so that JS is independent of HTML. So I can:
a) define one JS file for each .aspx page (which seems kind of stupid)
b) put all the code into one file - but then all code runs for every .aspx page that is executed. So if I have, for example, Map.aspx for wich the document.ready() function manipulates a map, and Calendar.aspx for which the document.ready() function manipulates a calendar, if I place all this code into one external document.ready() function, then all this code will run for both the Map.aspx and Calendar.aspx pages.
How do I solve this issue?