最近写 ASP.NET 中出现的错误 & 实现DataTable和DataSet类型的客户端/服务器端自动转换...

CausesValidation 属性设置:未设置为 False 而导致 Ajax 回调时无反应,或设置了 True 而导致即使输入不合要求也提交后台处理(在无 Submit Button 情况下)

客户端调用 WebService ,其中 WebService 返回的是 DataSet 对象 :出现错误提示“WebMethod Dataset System.InvalidOperationException: A circular reference was detected......”

解决方法:

1. 在 WebService 方法前添加 [System.Web.Script.Services.ScriptMethod],如下:

1  [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Xml)]
2  public  DataSet GetData()
3 
4  }

不过这种方法返回的是 XML ,客户端调用 WebService 方法后,返回的是 XML 文档内容。

 

2.在 Web.Config 文件启用ASP.NET AJAX Futures CTP中自带的DataTable和DataSet相关JavaScriptConverter组件(参见:SP.NET AJAX异步调用Web Service和页面中的类方法 - 服务器端和客户端数据类型的自动转换(续4)),如下:

首先,确保项目引用了 Microsoft.Web.Preview.dll 程序集。(去http://go.microsoft.com/fwlink/?LinkID=77294下载"Microsoft ASP.NET AJAX

Futures CTP" 安装好后,在默认安装文件夹(C:"Program Files"Microsoft ASP.NET"ASP.NET 2.0 AJAX Futures January CTP"v1.0.61025)中可以找到.)ASP.NET AJAX Futures CTP:这一部分就是被ASP.NET AJAX暂时“抛弃”的原有CTP版本中“非核心”的部分,也叫做“Value-add”包,其中包括服务器端的扩展器控件(Extender Control)、Web部件,客户端的各种控件、拖放功能实现、ASP.NET AJAX XML脚本等。所谓“抛弃”,实际上只是意味着微软公司暂时不会对这些内容进行官方的支持,而选择使用“社区支持”的方法。这样,微软公司将不会为这部分 内容提供详细的开发文档,开发者只能在社区中互相讨论以找到问题的解决方案。若要安装这部分内容,则必须首先安装“核心”部分的ASP.NET 2.0 AJAX Extensions。(参见:ASP.NET Ajax程序设计—第I卷第2章第3节

添加引用后,则再 Web.config 文件中添加如下内容:

< system.web.extensions >  
< scripting >  
< webServices >  
< jsonSerialization >  
< converters >  
< add  name ="DataSetConverter"  type ="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview" />  
< add  name ="DataRowConverter"  type ="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview" />  
< add  name ="DataTableConverter"  type ="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview" />  
</ converters >  
</ jsonSerialization >  
</ webServices >  
</ scripting >  
</ system.web.extensions >

 在添加上面的内容是,要先设置构架,如下:

< configSections >
    
< sectionGroup  name ="system.web.extensions"  type ="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" >
      
< sectionGroup  name ="scripting"  type ="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" >
          
< section  name ="scriptResourceHandler"  type ="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  requirePermission ="false"  allowDefinition ="MachineToApplication" />
        
< sectionGroup  name ="webServices"  type ="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" >
          
< section  name ="jsonSerialization"  type ="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  requirePermission ="false"  allowDefinition ="Everywhere"   />
          
< section  name ="profileService"  type ="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  requirePermission ="false"  allowDefinition ="MachineToApplication"   />
          
< section  name ="authenticationService"  type ="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"  requirePermission ="false"  allowDefinition ="MachineToApplication"   />
        
</ sectionGroup >
      
</ sectionGroup >
    
</ sectionGroup >
  
</ configSections >

 

一切 ok~哈哈~

 

转载于:https://www.cnblogs.com/nikytwo/archive/2009/05/15/1456999.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值