Take the 2-minute tour ×

If I add Items to a Select element at the client side and then submit the form, I get the following error:-


I do not want to disable the EventValidation. How can I register the data added at the client side to a particular element for postback validation at server side ?

I know the RegisterForEventValidation method is there, but I have never used it and even I don't understand from the msdn.

If anyone has ever done this, can you please share a sample code with brief explanation ?

share|improve this question
add comment

2 Answers

To be honest I never had good luck with this, I found it much easier to subclass the necessary control just in that particular case in order to avoid ASP.NET attempting to validate it. This is better than turning of validation for the page as everything but that control will still be validated as always. I'm assuming in your case you're using a server side HtmlSelect (same can be done with DropDownList). Here is one option:

public class NoEventValdationHtmlSelect : HtmlSelect

You'll have to retrieve the selected value via Request.Form[UniqueNameOfControl] since SelectedIndex/Value/Item will be null on the server side.

share|improve this answer
+1 for you reply. But I found the answer for my question that it is not entirely possible, but if I know the values that are going to be added on the client side in advance, then I can register those values to be valid post data for that control using Page.ClientScript.RegisterForEventValidation. Thanks! –  teenup Aug 5 '11 at 5:42
add comment
up vote 0 down vote accepted

In my case, I know all the values in advance that can be added to the ListBox at the Client side, so fortunately, there is a solution for this:-

protected override void Render(HtmlTextWriter writer)
 Page.ClientScript.RegisterForEventValidation(lstBox.UniqueID, "ListItemValue 
 that can be added at client side");
share|improve this answer
add comment

Your Answer


