Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to process events from Buttons inside Repeaters? And what's this EnableEventValidation thing?

Tags:

asp.net

I have a Repeater with a Button inside the ItemTemplate. I added the CommandName property to the button and registered and event handler for the ItemCommand event on the Repeater.

My problem is that when I click the button, I get an ArgumentException with a message saying something about EnableEventValidation being set to true.

(By the way, is there a way I can get the message in English, instead of a lousy Portuguese translation?)

I tried setting it to false and the ItemCommand handler is not called. If I set it to true I get the error.

The message also says something about using ClientScriptManager.RegisterForEventValidation if I trust the client (which I do). The problem is I can't make sense of the documentation for that method.

like image 600
R. Martinho Fernandes Avatar asked Jan 26 '26 02:01

R. Martinho Fernandes


2 Answers

lookout for the binding problem pointed out by Steve Robbins and you may also want to take a look at this article which I found pretty useful when I was stuck in a similar situation.

like image 81
Perpetualcoder Avatar answered Jan 27 '26 15:01

Perpetualcoder


The only time I've ever seen this is when I was rebinding the repeater in the Page_Load on postback, rather than wrapping the binding in an if (!Page.IsPostBack). If you do this then the control that's sending the message is effectively invalid, so it fails.

like image 30
Steven Robbins Avatar answered Jan 27 '26 16:01

Steven Robbins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!