Update: Dynamically Adding JavaScript To Select ASP.NET Content Pages / Master Pages Via The HtmlGenericControl Class
In a previous article, I had discussed the problem of applying JavaScript to only select content pages of a site that uses master pages.
I said there were four ways to go about it: Simply dumping your JavaScript on your content page (bad practice); add the JavaScript directly to the <head> section of your master page (bad practice); include an external JavaScript file to a <script> tag in your master page’s <head> section (good practice, but wasteful if you only need the script on a single page or few pages of a multi-page site); or use a ContentPlaceHolder in the <head> section, then use a Content tag on the content page to include your JavaScript (which the IDE hates, but will tolerate; and, which Microsoft does not specifically state is an OK practice).
I’ve done some follow-up research and found the right way to include JavaScript on a single page of an ASP.NET site that uses master pages: The HtmlGenericControl class.