Invalid postback or callback argument. Why?

人盡茶涼 提交于 2019-12-04 03:37:10

This has to be one of the most frustrating error messages in .NET, but once you get a feel for what's going on, it makes sense. .NET likes to know EVERYTHING that's going on. It keeps track of all the elements that it has placed on the page. Along those same lines, .NET gets offended when it receives input from something it didn't know about. In your case, it sounds like, at the time you click on the LinkButton, .NET doesn't think it should be there. In my experience, there are two likely reasons for this:

  1. You're doing to client-side wizardry that is creating new inputs or cloning existing inputs.

  2. While the form submission is being processed, .NET does something to the LinkButton which causes it to be no longer available. Some examples of this I've run into are when your LinkButton is dynamically created in the backend or you're using UpdatePanels and their content get changed during the form's submission.

Basically, I believe if you step through the form submission code and watch that LinkButton, you'll see .NET forget about it, which understandably triggers this "Security Exception" when the LinkButton is clicked.

If they're clicking before a page has a chance to fully render then the __EVENTVALIDATION fields aren't going to have been completely written - thus your error.

Now this was fixed in 3.5 SP1/3.0 SP2, and is configurable in web.config;

<configuration>
    <system.web>
        <pages renderAllHiddenFieldsAtTopOfForm="true"></pages>
    </system.web>
</configuration>

The default is true - so what version of .NET are you running? You could always disable the buttons client side until the page has finished loading.

This error was appearing intermittently for me, on a very large page.

I discovered that if a button was clicked before the page had completed loading, it would give this error.

Waiting for the page to load completely before clicking the button, I didn't get the error.

Use this in page.asx in the page tag EnableEventValidation="false"

I've found that html forms can cause this problem in WebForms if you don't remove them all from a template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!