包含的脚本引用,特别是jQuery,正在viewstate之后呈现.有没有办法在<head>中得到这个?
Page.ClientScript.RegisterClientScriptInclude("jQuery", "/scripts/jquery.js");
Run Code Online (Sandbox Code Playgroud)
我试图在用户控件的页面加载中注册jquery.js.
提前致谢!
PS如果无法完成(使用ClientScript),任何人都知道他们为什么不构建它?
UPDATE
我需要的ClientScript管理器的主要功能是只能包含一次脚本.控件可以在页面上出现多次,但我只想要一个jQuery脚本包含
Gle*_*lar 24
直接在HEAD中包含它:
HtmlGenericControl Include = new HtmlGenericControl("script");
Include.Attributes.Add("type", "text/javascript");
Include.Attributes.Add("src", sInclude);
this.Page.Header.Controls.Add(Include);
Run Code Online (Sandbox Code Playgroud)
在添加之前,您需要检查以确保它不存在.
我曾经有过这个问题,最后我没有使用RegisterClientScriptInclude.
我在页面的标题中放置了一个占位符,并通过HtmlGenericControl将脚本标记添加到占位符.
我会看看能否找到我的代码,然后用它来编辑我的答案.
编辑
我找不到我的代码,所以我只是重新创建它:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<asp:PlaceHolder runat="server" ID="HeadPlaceHolder"></asp:PlaceHolder>
</head>
<body>
...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
而守则背后:
protected void Page_Load(object sender, EventArgs e)
{
HeadPlaceHolder.Controls.Add(/* Your control here */);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21154 次 |
| 最近记录: |