The problem is that ASP.NET does not get to know about this extra or removed listitem. You got an number of options (listed below):
Disable eventvalidation (bad idea, because you lose a little of security that come with very little cost).
Use ASP.NET Ajax UpdatePanel. (Put the listbox in the Updatepanel and trigger a update, if you add or remove listbox. This way viewstate and related fields get updates and eventvalidation will pass.)
Forget client-side and use the classic postback and add or remove the listitems server-side
Please use update panel in your case and it will solve your problem. if you want I can send you some working example of update panel.
I hope this helps.
If my solution works for you, please mark it as answer! It will help others.
Get more information: http://codemovement.pk
According to official document, EnableEventValidation could allow us to get or set a value indicating whether the page validates postback and callback events.
If EnableEventValidation’s value is set to false, it indicate that page don’t validate postback and callback events,
However, RegisterForEventValidation is used to Registers an event reference for validation with a unique control ID and event arguments representing the client control generating the event.
When you set EnableEventValidation to true, 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.
When you set EnableEventValidation to false, it indicate that no event validation( neither built-in validation or some validation you register by using RegisterForEventValidation) will be triggered when page do postback and callback.
In a word, from my understanding, the function of the two is different, So, it is impossible to use 'RegisterForEventValidation' in place of 'EnableEventValidation="false"'
Best Regards
Cathy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
8 Points
41 Posts
How can I use 'RegisterForEventValidation' in place of 'EnableEventValidation="false"'
Oct 19, 2016 09:37 AM|vikas251074|LINK
How can I use 'RegisterForEventValidation' in place of 'EnableEventValidation="false"'
Vikas
Application Developer
Contributor
2340 Points
807 Posts
Re: How can I use 'RegisterForEventValidation' in place of 'EnableEventValidation="false"'
Oct 19, 2016 12:48 PM|codemovement.pk|LINK
Hi Vikas,
The problem is that ASP.NET does not get to know about this extra or removed listitem. You got an number of options (listed below):
Please use update panel in your case and it will solve your problem. if you want I can send you some working example of update panel.
I hope this helps.
Get more information: http://codemovement.pk
Thanks,
Star
8670 Points
2882 Posts
Re: How can I use 'RegisterForEventValidation' in place of 'EnableEventValidation="false"'
Oct 20, 2016 03:03 AM|Cathy Zou|LINK
Hi vikas251074,
According to official document, EnableEventValidation could allow us to get or set a value indicating whether the page validates postback and callback events.
If EnableEventValidation’s value is set to false, it indicate that page don’t validate postback and callback events,
However, RegisterForEventValidation is used to Registers an event reference for validation with a unique control ID and event arguments representing the client control generating the event.
When you set EnableEventValidation to true, 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.
When you set EnableEventValidation to false, it indicate that no event validation( neither built-in validation or some validation you register by using RegisterForEventValidation) will be triggered when page do postback and callback.
In a word, from my understanding, the function of the two is different, So, it is impossible to use 'RegisterForEventValidation' in place of 'EnableEventValidation="false"'
Best Regards
Cathy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.