开发者

Button in gridview

I'm using a button in a template field of gridview. On button click I want to redirect to another page but it throws an exception:

Invalid postback or callback argument. Event validation is enabled using 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.

What can I 开发者_StackOverflow中文版do to resolve this problem?


You could, in RowCreated, as in the previous answer's post, register each button for event validation. Also, I don't know if you have that problem if you define a commandname and commandargument, and then use the RowCommand event of the Grid, instead of the button click event, to redirect. You wouldn't need a template column; I think the GridButtonColumn would work for this too...

Lastly, you could mitigate this with Javascript, to redirect by setting window.location = 'newurl'; you can render out a URL, which is affected from the server side inside the template.


The problem is that ASP.NET does not get to know about this gridview button. You got an option (listed below):

  • Disable eventvalidation (bad idea, because you lose a little of security that come with very little cost.)

or have a look at this: http://odetocode.com/blogs/scott/archive/2006/03/21/asp-net-event-validation-and-invalid-callback-or-postback-argument-again.aspx.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜