locked
How can I use 'RegisterForEventValidation' in place of 'EnableEventValidation="false"' RRS feed

  • Question

  • User390265149 posted

    How can I use 'RegisterForEventValidation' in place of 'EnableEventValidation="false"'

    Wednesday, October 19, 2016 9:37 AM

All replies

  • User-691209617 posted

    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):

    • 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.

    Wednesday, October 19, 2016 12:48 PM
  • User-707554951 posted

    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

    Thursday, October 20, 2016 3:03 AM