如何获得Page.ClientScript.RegisterClientScriptInclude在头包括哪些内容? [英] How to get Page.ClientScript.RegisterClientScriptInclude to include in the head?

查看:290
本文介绍了如何获得Page.ClientScript.RegisterClientScriptInclude在头包括哪些内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所包含的脚本引用,尤其是jQuery的,正在视图状态后呈现。有没有办法在&lt得到这一点; HEAD>

The included script references, in particular jQuery, are being rendered after viewstate. Is there a way to get this in the < head>?

Page.ClientScript.RegisterClientScriptInclude("jQuery", "/scripts/jquery.js");

我想在用户控件的页面加载注册的jquery.js。

I am trying to register jquery.js in a user control's page load.

在此先感谢!

P.S。如果不能这样做(与ClientScript),任何人有一个想法,为什么他们不建造起来?

P.S. If it can't be done (with ClientScript), anyone have an idea why they didn't build it in?

更新

在ClientScript经理,我需要的主要特点是只包含一个脚本一次的能力。控制可以在页面上出现了很多次,但我只想要一个jQuery脚本包含

The main feature of the ClientScript manager I need is the ability to only include a script once. The control can appear many times on a page, but i only want one jQuery script include

推荐答案

直接inlcude它的头部:

to directly inlcude it in the HEAD:

HtmlGenericControl Include = new HtmlGenericControl("script"); 
Include.Attributes.Add("type", "text/javascript"); 
Include.Attributes.Add("src", sInclude); 
this.Page.Header.Controls.Add(Include);

你想检查,以确保它已经不存在添加它之前。

you would want to check to make sure its not there already before adding it.

这篇关于如何获得Page.ClientScript.RegisterClientScriptInclude在头包括哪些内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆