使用jQuery作为ASP.NET嵌入式webresource [英] Using JQuery as an ASP.NET embedded webresource

查看:167
本文介绍了使用jQuery作为ASP.NET嵌入式webresource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有依赖于JQuery的某些功能的ASP.NET服务器控件。我试图添加为webresource。

I have an ASP.NET server control which relies on JQuery for certain functionality. I've tried to add as a webresource.

我的问题是我包括jQuery的文件的方法,将它添加到身体,或窗体确切:

My problem is my method of including the jquery file adds it to the body, or the form to be exact:

this.Page.ClientScript.RegisterClientScriptInclude(...)

这另一种方法是将其添加为一个文本头标记:

The alternative to this is to add it as a literal in the head tag:

LiteralControl include = new LiteralControl(jslink);
this.Page.Header.Controls.Add(include);

的问题,这是但在使用JQuery失败,因为jQuery是后来载入头部的任何现有code索马里红新月会(ASP.NET增加了文字在控制树的底部)。

The problem with this however is any existing code srcs in the head which use JQuery fail, as JQuery is loaded afterwards (ASP.NET adds the literal at the bottom of the control tree).

是否有使JQuery的嵌入的资源的一个实际的方法,但在头装第一?或者我应该现在放弃了。

Is there a practical way of making JQuery an embedded resource, but loaded in the head first? Or should I give up now.

推荐答案

更新:

做的更容易的方式就是动态添加脚本标签,在你的脚本,并指向谷歌code托管。例如。

A far easier way of doing it is to simply add the script tag dynamically, in your script and point to the google code hosting. e.g.

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

include_dom("http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js");

该功能从这篇文章采取

The function is taken from this article


Crecentfresh把我推在正确的方向,我也发现

Crecentfresh pushed me in the right direction, I also found

http://en.csharp-online.net/Creating_Custom_ASP.NET_AJAX_Client_Controls—IScriptControl.GetScriptReferences_Method.

http://en.csharp-online.net/Creating_Custom_ASP.NET_AJAX_Client_Controls—IScriptControl.GetScriptReferences_Method.

我的问题仍然存在,虽然下,ScriptManager在头部的脚本之后添加引用,但我认为这是解决不了的问题。我选择来回答自己,但也upvoted crescentfresh。

My problem still remains though, the ScriptManager adds the references after the script in the head but I think this is an issue that can't be resolved. I've opted to answer myself but also upvoted crescentfresh.

这篇关于使用jQuery作为ASP.NET嵌入式webresource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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