在试图理解为什么客户端代码没有呈现在页面中(由用户控件注入)后,我找到了这个链接,事实证明你必须有一个表单标签才能工作(Page.RegisterClientScriptBlock确实声明了这一点,但我的ClientScriptManager.RegisterClientScriptBlock use 对此没有任何说明)。
我正在使用 Visual Studio 2005。
有谁知道这是否已解决?
编辑:
为了澄清,我希望我的控件将 javascript 代码添加到页面的 head 部分,而不必使用
<form runat="server"
我尝试使用以下方法添加它:
HtmlGenericControl x = new HtmlGenericControl("script");
x.InnerText = "alert('123');";
Page.Header.Controls.Add(x);
但这对我不起作用。