简体   繁体   中英

Invalid postback or callback argument error when submitting form with Button but not with LinkButton

I have a form where I dynamically populate a DropDownList using Jquery's ajax function to retrieve a list of values from a web service. I originally had a Button control which submitted the form. This caused the "exception:Invalid postback or callback argument. Event validation is enable...." error.

After researching options, such as disabling event validation (bad) and registering for event validation (which would not work in this case) the best option seemed to be to swap the Button control for a LinkButton control. I did this and, sure enough, it works fine now.

My question is...why?

What is different about the LinkButton that means that it does not cause the event validation error and have I, by changing to a LinkButton, introduced a new security risk because event validation isn't happening?

The postback validation error is happening because the data you send back at the postback is no the same than when it was sent by the server.

You should take a look at this blog post by Scott K. Allen. He suggests to add all the possible values for your dropdown in the Render event for your web page.

You could also create your own version of the DropDownList since it won't require event validation as this guy suggests .

My personnal take is that you might have to rethink how you interact with your data. If you need to feed dynamically your DropDownList and you use ASP.NET WebForms then you are required to have a PostBack for that. You could use a UpdatePanel to make it feel "Ajax" if you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM