容器标签可以放在HEAD中吗?

发布于 2024-08-18 03:21:37 字数 669 浏览 4 评论 0原文

在文档的 标记部分中,我有代码可以让我使用 JavaScript 中的 asp.net 控件的 Id,如下所示:

<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>

但是,如果我想修改页面结构在页面生命周期的后期阶段,它会给我一个错误,因为我在那里有 ASP 标签。解决方法是将 ASP 标记包含在服务器控件中,如下所示:

<div id="customerIdContainer" runat="server">
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
</div>

但随后我收到一条警告,指出 head 标记中不允许使用 div 标记。那么是否有一个在头部有效的容器标签,我可以添加 runat="server" 以使其成为服务器控件,以便我可以在没有警告的情况下解决此问题?

In a section in the <head> tags of my document I have code that lets me use the Id of my asp.net control from JavaScript like this:

<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>

However, if I want to modify the page structure in later stages of the page life cycle, it give me an error because I have the ASP tags in there. A work-around is enclosing the ASP tags in a server control like this:

<div id="customerIdContainer" runat="server">
<script language="javascript" type="text/javascript">
var customerId = '<%= Me.CustomerTextbox.ClientID %>';
</script>
</div>

But then I get a warning that a div tag is not allowed in the head tag. So is there a container tag that is valid in the head that I can add runat="server" to to make it a server control so I can workaround this problem without the warnings?

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

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

发布评论

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

评论(2

待"谢繁草 2024-08-25 03:21:37

一些想法:

  • 你能把“head”变成“runat=sever”吗?
  • 如果您使用>在 head 标签内,会抱怨吗?如果没有,您可以从代码中向占位符添加控件。
  • 脚本可以存在于 head 标签之外,因此只需移动它即可。

Some thoughts:

  • Can you just make "head" into "runat=sever"?
  • If you use <asp:placeHolder id="whatever" runat="server" /> inside the head tag, will that complain? If not, you can add controls to the placeholder from the code.
  • Scripts can exist outside of the head tags, so just move it.
我三岁 2024-08-25 03:21:37

将 script 标签移到 head 部分之外。 ;-)

Move the script tag outside the head section. ;-)

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