ASP.NET AJAX 1.0 Beta 2 的一个重要改变

本文介绍了解决使用Ajax ASP.NET Extension 2.0 Beta版本时遇到的Sys.ScriptLoadFailedException异常的方法,并展示了如何正确地通知脚本加载完成及使用集合类型验证的例子。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   在用Ajax asp.net  Extension 2.0 beta 的时候遇到一个问题,在加载以前的javascript的时候出错,Sys.ScriptLoadFailedException..................  在这里找到了答案

 

这个错误主要是因为在beta2 中,通过ScriptManage加入script 的时候采用了异步的方式,所以在javascript文件的最后要加多一句

if (Sys  &&  Sys.Application) {     
      Sys.Application.notifyScriptLoaded();
 } 

否则你就会有一个Sys.ScriptLoadFailedException。

PS:最近真的被这个版本搞s了,错了都不知道怎么错了,官方那里就那么一点文档,郁闷s。。。。。。

 


 

还有一个改进。就是对丰富了collections类型,详细请看这里吧

例子:

注意:[{name: 'customer', type: Samples.Customer, mayBeNull: false, isOptional: false}]);      是对Collection的数据类型的验证,也就是改进的地方。

Type.registerNamespace( ' Samples ' );  
Samples.Customer 
=   function () {    
         
this ._fullName; 

Samples.Customer.prototype 
=  { 
    set_fullName : 
function (value) { 
        
this ._fullName  =  value;    
    },
    get_fullName : 
function () { 
        
return   this ._fullName;     
    } 

Samples.Customer.registerClass(
' Samples.Customer ' ); 

Samples.CustomerCollection = function() {
    this._innerList = [];
}
Samples.CustomerCollection.prototype = {
    addCustomer : function(customer) {
        this._validateCustomer(arguments);
        
        Array.add(this._innerList, customer);
    },
    
    removeCustomer : function(customer) {
        this._validateCustomer(arguments);
        
        Array.remove(this._innerList, customer);
    },
    
    get_count : function() {
        return this._innerList.length;
    },
    
    _validateCustomer : function(args) {
        var e = Function._validateParams(args,
            [{name: 'customer', type: Samples.Customer, mayBeNull: false, isOptional: false}]);
            
        if(e) throw e;
    }
}
Samples.CustomerCollection.registerClass('Samples.CustomerCollection');

//调用
function pageLoad() {
    var c1 = new Samples.Customer();
    c1.set_fullName('John Doe');
    
    var c2 = new Samples.Customer();
    c2.set_fullName('John Smith');
    
    var coll = new Samples.CustomerCollection();
    coll.addCustomer(c1);
 
    coll.addCustomer("blah"); // This will throw.
    
    coll.removeCustomer(c1);
    alert(coll.get_count());
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值