Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新面板内的刷新GridView_C#_Asp.net_Asp.net Ajax - Fatal编程技术网

C# 更新面板内的刷新GridView

C# 更新面板内的刷新GridView,c#,asp.net,asp.net-ajax,C#,Asp.net,Asp.net Ajax,我有一个包含在更新面板中的gridview。我使用gridview中的一个按钮编辑gridview中的一条记录,它会更新面板回发(_doPostBack),然后更新gridview的数据集,并尝试使用新数据源刷新griview,但出现以下错误 我重新绑定gridview,如下所示: gvwSearchResult.DataSource = dsP1.prSearchItem; gvwSearchResult.DataBind(); UpdatePanel1.Update(); Uncaught

我有一个包含在更新面板中的gridview。我使用gridview中的一个按钮编辑gridview中的一条记录,它会更新面板回发(_doPostBack),然后更新gridview的数据集,并尝试使用新数据源刷新griview,但出现以下错误

我重新绑定gridview,如下所示:

gvwSearchResult.DataSource = dsP1.prSearchItem;
gvwSearchResult.DataBind();
UpdatePanel1.Update();

Uncaught Sys.WebForms.PageRequestManagerServerErrorException:   
 Sys.WebForms.PageRequestManagerServerErrorException:
 Invalid postback or callback argument.  
 Event validation is enabled using <pages enableEventValidation="true"/> in configuration or 
<%@ Page EnableEventValidation="true" %> in a page.
 For security purposes, 
this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or 
callback data for validation.
Sys.WebForms.PageRequestManager._endPostBackScriptResource.axd:307
Sys.WebForms.PageRequestManager._parseDeltaScriptResource.axd:749
Sys.WebForms.PageRequestManager._onFormSubmitCompletedScriptResource.axd:584
(anonymous function)ScriptResource.axd:22
(anonymous function)ScriptResource.axd:1519
Sys.Net.WebRequest.completedScriptResource.axd:2924
_onReadyStateChange
gvwSearchResult.DataSource=dsP1.prSearchItem;
gvwSearchResult.DataBind();
UpdatePanel1.Update();
未捕获Sys.WebForms.PageRequestManagerServerErrorException:
Sys.WebForms.PageRequestManagerServerErrorException:
回发或回调参数无效。
使用配置中的或启用事件验证
在一页中。
为了安全起见,
此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。
如果数据有效且符合要求,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回发
用于验证的回调数据。
Sys.WebForms.PageRequestManager.\u endPostBackScriptResource.axd:307
Sys.WebForms.PageRequestManager.\u parseDeltaScriptResource.axd:749
Sys.WebForms.PageRequestManager.\u onFormSubmitCompletedScriptResource.axd:584
(匿名函数)ScriptResource.axd:22
(匿名函数)ScriptResource.axd:1519
Sys.Net.WebRequest.completedScriptResource.axd:2924
_onReadyStateChange

有什么想法吗?

您是否将gridview绑定到pageLoad中?如果是,请检查

if(!Page.IsPostBack)
 {
     //Bind your gridview.
 }

您的控件可能在数据绑定之前重新生成。如果在执行删除操作之前绑定控件,则可能会发生这种情况。在pageLoad和button事件下检查代码。只有数据绑定在最后,而不是在中间。

此错误是由EventValidation失败引起的。下面的线程显示了如何调试此类异常


确保您的按钮已使用SubmitBehavious属性设置为false。应将其呈现为输入类型=“按钮”而不是“提交”。不知道为什么,但对我来说,这项更改起作用了。

我设置EnableEventValidation=“false”之后,它就起作用了。但不确定正确的操作方式

编辑按钮是自动生成的还是在模板中?我正在将其绑定到更新面板加载、受保护的void UpdatePanel1_加载(对象发送器、事件参数e){}是。。我确实更新了updatepanel,我的网格在更新面板的内部。