只能在执行Render() 的过程中调用 RegisterForEventValidation
2009-03-25 18:29
471 查看
在实现"将GridView中的数据导出到Excel中"的时候出现了如下错误:
用户代码未处理 InvalidOperationException
只能在执行 Render() 的过程中调用 RegisterForEventValidation;
EnableEventValidation属性是 .NET Framework 2.0 中是新增的属性,默认的情况下该属性的值为true;通过这个新增的功能ASP.NET会检查 POST方法中的所带的参数,如果认为不合法,就会抛出异常。这个设计的目的是为了防止恶意用户利用post 方法发送一些恶意数据,但是有时也会出现类似上面的错误。
只要禁止这个功能,问题就能得到解决。可以通过以下两种途径解决:
1、在Web.Config文件中:在<system.web></system.web>标记中添加如下代码:
<system.web>
<pages enableEventValidation="false"> </pages>
</system.web>
2、在具体的.aspx页面的源代码中修改代码,如下:
<%@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true" CodeFile="GridView_Export_Excel.aspx.cs" Inherits="GridView_Export_Excel" %>
用户代码未处理 InvalidOperationException
只能在执行 Render() 的过程中调用 RegisterForEventValidation;
EnableEventValidation属性是 .NET Framework 2.0 中是新增的属性,默认的情况下该属性的值为true;通过这个新增的功能ASP.NET会检查 POST方法中的所带的参数,如果认为不合法,就会抛出异常。这个设计的目的是为了防止恶意用户利用post 方法发送一些恶意数据,但是有时也会出现类似上面的错误。
只要禁止这个功能,问题就能得到解决。可以通过以下两种途径解决:
1、在Web.Config文件中:在<system.web></system.web>标记中添加如下代码:
<system.web>
<pages enableEventValidation="false"> </pages>
</system.web>
2、在具体的.aspx页面的源代码中修改代码,如下:
<%@ Page Language="C#" EnableEventValidation="false" AutoEventWireup="true" CodeFile="GridView_Export_Excel.aspx.cs" Inherits="GridView_Export_Excel" %>
相关文章推荐
- GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用RegisterForEventValidation的错误提示
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render(); )
- 问题:只能在执行 Render() 的过程中调用 RegisterForEventValidation;结果:只能在执行 Render() 的过程中调用 RegisterForEventValidation
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render();
- 当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render(); )
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render();
- 只能在执行Render() 的过程中调用 RegisterForEventValidation
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation
- 只能在执行Render() 的过程中调用 RegisterForEventValidation;
- 异常“只能在执行Render()的过程中调用RegisterForEventValidation”的解决办法(转)
- 当用GridView导出Execl的时候,会发生只能在执行 Render() 的过程中调用 RegisterForEventValidation的错误提示
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation
- C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation
- "只能在执行Render()的过程中调用RegisterForEventValidation" 解决方案
- Error 之 只能在执行Render() 的过程中调用 RegisterForEventValidation;
- C#中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render()
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render()
- 只能在执行 Render() 的过程中调用 RegisterForEventValidation