【发布时间】:2011-08-31 22:45:05
【问题描述】:
由于各种原因,我无法标记我的<head> 标签runat="server"。我还有其他方法可以访问它并在其下方附加文字吗?我需要添加一个脚本(作为文字)并让它成为<head> 标签内部引用的第一个脚本。
也许使用 FindControl?
【问题讨论】:
标签: asp.net webforms page-lifecycle
由于各种原因,我无法标记我的<head> 标签runat="server"。我还有其他方法可以访问它并在其下方附加文字吗?我需要添加一个脚本(作为文字)并让它成为<head> 标签内部引用的第一个脚本。
也许使用 FindControl?
【问题讨论】:
标签: asp.net webforms page-lifecycle
可以声明 Literal 服务器控件而不将 head 元素定义为服务器控件:
<head>
<asp:Literal ID="literal1" runat="server"></asp:Literal>
<title></title>
</head>
使用它,您可以根据需要从后面的代码中添加内容:
protected void Page_Load(object sender, EventArgs e)
{
literal1.Text = "<script type=\"text/javascript\" src=\"scripts.js\"></script>";
}
【讨论】:
您只能使用FindControl 来查找控件,即作为服务器控件的元素。所有其他元素仅作为文本控件中的文本处理。
你可以在head标签中放一个PlaceHolder控件,然后你可以在里面添加文字控件。
【讨论】: