Some background. The project is a VS 2005 Web Application using ASP.NET AJAX Extensions 1.0.
一些背景知识。该项目是一个使用ASP的vs2005 Web应用程序。1.0净AJAX扩展。
Question, How can I reference the JavaScript files that are used by the Scriptmanager control, without using the ScriptManager control or how can I load the ScriptManager JS files earlier (I don't think this is possible as the ScriptManager has to be in the server-side form tag)?
问题是,如何在不使用Scriptmanager控件的情况下引用Scriptmanager控件使用的JavaScript文件,以及如何在更早的时候加载Scriptmanager JS文件(我不认为这是可能的,因为Scriptmanager必须位于服务器端表单标记中)?
I have a ScriptManager control in a master page, but a lot of times, there are pages that are just good ol' non-async postbacks and I create client-side objects before the script manager has loaded. Now I know it's good practice to load scripts near the end of the markup and CSS at the start, but in my case, some of the scripts I create need to be before, typically in the head tag because for example I'll have a repeater that instantiates a client-side object.
我在一个主页面中有一个ScriptManager控件,但是很多时候,有些页面只是很好的ol' non-async回发,我在脚本管理器加载之前创建客户端对象。现在我知道这是好的做法附近加载脚本的标记和CSS开始,但是在我的例子中,我创建的脚本需要之前,通常在头部标签因为例如我要实例化一个客户端对象的中继器。
So this is what I'd like:
这就是我想要的:
// My scripts
/ /我的脚本
Right now this is what I do to get around the issue:
现在我要做的就是解决这个问题:
(function() {
var myInterval;
myInterval = setInterval(function() {
if (!Type) {
return;
}
clearInterval(myInterval);
Type.registerNamespace("Awesome");
Awesome.Widget = function() {
var _this = this;
this.myProperty = 'This is awesome';
}
}, 40);
})();
or I do this:
或者我这样做:
var Awesome = {};
Awesome.Widget = function {
/// Awesome code.
}
As well it would be nice to not load these scripts twice as the ScriptManager control will render at some point since it's in my MasterPage.
同样,最好不要加载这些脚本两次,因为ScriptManager控件在我的主页中。
Maybe the problem is I'm going about this the wrong way. Any help is greatly appreciated.
也许问题是我走错了路。非常感谢您的帮助。
2 个解决方案
#1
2
As you are using the MS AJAX controls, you can take advantage of the automatically wired pageLoad function name, and put the code in there.
在使用MS AJAX控件时,可以利用自动连接的pageLoad函数名,并将代码放在其中。
Your pageLoad function is called when the document is ready, everything's loaded, and you are good to muck around with the DOM to your hearts content (it's a bit like jQuery's document.ready function, but actually fires slightly later).
当文档准备好、所有内容都已加载时,就会调用pageLoad函数,您最好将DOM与您的核心内容混合在一起(这有点像jQuery的文档)。就绪函数,但实际上稍后会稍微启动)。
More details can be found on the AJAX Client Life-Cycle Events page.
更多细节可以在AJAX客户端生命周期事件页面找到。
function pageLoad(sender, args){
Type.registerNamespace("Awesome");
Awesome.Widget = function() {
var _this = this;
this.myProperty = 'This is awesome';
}
}
If you are not fussed about the document being ready, but can content yourself with all scripts being loaded and parse, you could hook into the init event instead.
如果您不担心文档是否准备好,但是可以对所有脚本加载和解析感到满意,那么您可以将其挂接到init事件中。
// Attach a handler to the init event.
Sys.Application.add_init(applicationInitHandler);
function applicationInitHandler() {
Type.registerNamespace("Awesome");
Awesome.Widget = function() {
var _this = this;
this.myProperty = 'This is awesome';
}
}
#2
0
I'm not sure I follow your question but hopefully this will help. The standard method to ensure you have access the the ASP.NET AJAX client-side libraries is to add a ScriptManager control to your Master Page and then to use ScriptManagerProxy controls in Content Pages, User Controls and Web Parts when needed.
我不太明白你的问题,但希望这能帮上忙。标准的方法来确保您能够访问ASP。NET AJAX客户端库将ScriptManager控件添加到主页面,然后在需要时在内容页面、用户控件和Web部件中使用ScriptManagerProxy控件。
The settings from the ScriptManagerProxy controls are combined with those of the ScriptManager in the Master Page to ensure the proper JavaScript code is made available to the page.
ScriptManagerProxy控件的设置与主页中的ScriptManager控件的设置相结合,以确保页面可以使用适当的JavaScript代码。
#1
2
As you are using the MS AJAX controls, you can take advantage of the automatically wired pageLoad function name, and put the code in there.
在使用MS AJAX控件时,可以利用自动连接的pageLoad函数名,并将代码放在其中。
Your pageLoad function is called when the document is ready, everything's loaded, and you are good to muck around with the DOM to your hearts content (it's a bit like jQuery's document.ready function, but actually fires slightly later).
当文档准备好、所有内容都已加载时,就会调用pageLoad函数,您最好将DOM与您的核心内容混合在一起(这有点像jQuery的文档)。就绪函数,但实际上稍后会稍微启动)。
More details can be found on the AJAX Client Life-Cycle Events page.
更多细节可以在AJAX客户端生命周期事件页面找到。
function pageLoad(sender, args){
Type.registerNamespace("Awesome");
Awesome.Widget = function() {
var _this = this;
this.myProperty = 'This is awesome';
}
}
If you are not fussed about the document being ready, but can content yourself with all scripts being loaded and parse, you could hook into the init event instead.
如果您不担心文档是否准备好,但是可以对所有脚本加载和解析感到满意,那么您可以将其挂接到init事件中。
// Attach a handler to the init event.
Sys.Application.add_init(applicationInitHandler);
function applicationInitHandler() {
Type.registerNamespace("Awesome");
Awesome.Widget = function() {
var _this = this;
this.myProperty = 'This is awesome';
}
}
#2
0
I'm not sure I follow your question but hopefully this will help. The standard method to ensure you have access the the ASP.NET AJAX client-side libraries is to add a ScriptManager control to your Master Page and then to use ScriptManagerProxy controls in Content Pages, User Controls and Web Parts when needed.
我不太明白你的问题,但希望这能帮上忙。标准的方法来确保您能够访问ASP。NET AJAX客户端库将ScriptManager控件添加到主页面,然后在需要时在内容页面、用户控件和Web部件中使用ScriptManagerProxy控件。
The settings from the ScriptManagerProxy controls are combined with those of the ScriptManager in the Master Page to ensure the proper JavaScript code is made available to the page.
ScriptManagerProxy控件的设置与主页中的ScriptManager控件的设置相结合,以确保页面可以使用适当的JavaScript代码。