Web用户控件中的外部JS文件?

发布于 2024-07-08 12:41:48 字数 349 浏览 4 评论 0原文

在 html 页面中,我们使用 head 标签添加对外部 .js 文件的引用。我们还可以在正文中包含 script 标签。但是我们如何在 Web 用户控件中包含外部 .js 文件呢?

经过一番谷歌搜索后我得到了这个。 它有效,但这是唯一的方法吗?

ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "MyUniquekey", @"<script src=""myJsFile.js"" type=""text/javascript""></script>", false);

——祖海布

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

且行且努力 2024-07-15 12:41:48

你也可以使用

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

这就是我总是这样做的方式

You can also use

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

That's the way I always do it anyway

何止钟意 2024-07-15 12:41:48

是的,这也有效..但是为什么所有的
脚本被转储到正文中并且
不在脑子里??

此处有一个潜在的解决方法

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

抱着落日 2024-07-15 12:41:48

关于正文中需要 Javascript,这是不正确的。

Javascript 函数将位于头部未执行,并且完全不受元素仍在加载这一事实的影响。

通常,页面末尾有一个调用来开始执行顶部的脚本。
(其他可用方法)

脚本被转储到正文中的唯一原因是因为 MS 似乎对 JavaScript 不感兴趣。
遗憾的是,因为强迫我们所有人正确使用 .NET,只会让世界充满缓慢的页面,这些页面不必要地在服务器上来回运行以满足最小的需求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文