asp.net - External JS file in web user control? - Stack Overflow

In a html page we use the head tag to add reference to our external .js files .. we can also include sc

In a html page we use the head tag to add reference to our external .js files .. we can also include script tags in the body .. But how do we include our external .js file in a web user control?

After 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

In a html page we use the head tag to add reference to our external .js files .. we can also include script tags in the body .. But how do we include our external .js file in a web user control?

After 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

Share Improve this question asked Nov 11, 2008 at 7:01 ZuhaibZuhaib 1,4203 gold badges18 silver badges36 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

You can also use

Page.ClientScript.RegisterClientScriptInclude("key", "path/to/script.js");

That's the way I always do it anyway

Yes this works too .. but why does all the script gets dumped in the body and not in the head??

There's a potential workaround for that here

That's kind of incorrect .. about needing the Javascript in the body.

A Javascript function would sit in the head unexecuted and not at all affected by the fact that elements are still to load.

Often there is a single call at the end of a page to start execution of scripts at the top. (Other methods available)

The only reason that script gets dumped in the body, is because MS doesn't seem to give 2 hoots about JavaScript. Shame, because forcing us all to use .NET proper, just makes the world full of sluggish pages that needlessly run back and forth to servers for the tiniest requirmenet.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744748407a4591445.html

相关推荐

  • asp.net - External JS file in web user control? - Stack Overflow

    In a html page we use the head tag to add reference to our external .js files .. we can also include sc

    7小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信