2012-03-12 107 views
1

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

我重新绑定我的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 

任何想法?

+0

编辑按钮是自动生成还是在模板中? – mslliviu 2012-03-12 07:41:24

+0

这是一个模板字段 – Roshe 2012-03-12 07:45:23

回答

1

你在pageLoad里绑定了你的gridview吗?如果是,那么请检查

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

您的控件可能在数据绑定之前重新生成。如果您在删除操作之前绑定了控件,则会发生这种情况。在按钮事件下也检查pageLoad &下的代码。只有数据绑定在最后的&之间。

+0

我将其绑定在我的更新面板加载中, protected void UpdatePanel1_Load(object sender,EventArgs e) {} – Roshe 2012-03-12 07:46:22

+0

检查我的更新回复。 – 2012-03-12 07:53:33

1

此错误是由于EventValidation失败而导致的。下面的线程显示了如何调试这些异常。

Conditional update panel

+0

是的,我更新了更新面板,我的网格在更新面板中。 – Roshe 2012-03-12 10:14:26

0

确保您的按钮UseSubmitBehaviour属性设置为false。它应该呈现为输入类型=“按钮”而不是“提交”。不知道为什么,但对我来说,这个变化工作..

0

我设置EnableEventValidation =“false”然后它的工作。但不知道正确的做法