您的位置:首页 > 编程语言 > ASP

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

2009-05-15 16:54 811 查看
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],如下:

[System.Web.Script.Services.ScriptMethod(ResponseFormat=System.Web.Script.Services.ResponseFormat.Xml)]

public DataSet GetData()

{

}
不过这种方法返回的是 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~哈哈~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐