最近写 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~哈哈~
客户端调用 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~哈哈~
相关文章推荐
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(9):服务器端和客户端数据类型的自动转换:DataTable和DataSet
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(9):服务器端和客户端数据类型的自动转换:DataTable和DataSet
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(9):服务器端和客户端数据类型的自动转换:DataTable和DataSet
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(7):服务器端和客户端数据类型的自动转换:泛型集合类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(5):服务器端和客户端数据类型的自动转换:基本类型和枚举类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法:服务器端和客户端数据类型的自动转换:复杂类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(6):服务器端和客户端数据类型的自动转换:复杂类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(7):服务器端和客户端数据类型的自动转换:泛型集合类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(8):服务器端和客户端数据类型的自动转换:数组类型
- 使用ASP.NET AJAX异步调用Web Service和页面中的类方法(10):服务器端和客户端数据类型的自动转换:以XML方式序列化数据、小结
- ASP.NET AJAX客户端编程之旅(三)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化
- [导入]ASP.NET AJAX客户端编程之旅(三)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化
- ASP.NET AJAX客户端编程之旅(三)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化
- ASP.NET AJAX客户端编程教程(3)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化
- ASP.NET AJAX客户端编程之旅(三)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化
- ASP.NET AJAX客户端编程之旅(三)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化(转载)
- JS实现将Asp.Net的DateTime Json类型转换为标准时间的方法