External JS file in web user control?
In the html page, we use the head tag to add a link to our external .js files. We can also include script tags in the body. But how can we include our external .js file in the web user control?
After a little googling, I got this. It works, but is this the only way?
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "MyUniquekey", @"<script src=""myJsFile.js"" type=""text/javascript""></script>", false);
- Zuhaib
source to share
So wrong .. about the need to use Javascript in the body.
The Javascript function will sit in your head unfulfilled and not at all affected by the fact that the elements are still loading.
Often there is one call at the end of the page to start executing the scripts at the top. (Other methods available)
The only reason the script gets dumped into the body is because MS doesn't seem to give 2 hoots about JavaScript. Shame, because forcing us all to use .NET just makes the world full of sluggish pages that uselessly run back and forth to servers for minimal requirmenet.
source to share