System. argumentexception: the callback or callback parameter is invalid. Use <pages enableeventvalidation = "true"/>

Source: Internet
Author: User

Note: An unhandled exception occurs during the execution of the current Web request. Check the stack trace information for details about the error and the source of the error in the code.
Exception details: system. argumentexception: the error message returned or the callback parameter is invalid. Use <pages enableeventvalidation = "true"/> in the configuration, or use <% @ page enableeventvalidation = "true" %> On the page to enable event verification. For security purposes, this function verifies whether the parameters of the send-back or callback events come from the server controls that initially present these events. If the data is valid and is expected, use the clientscriptmanager. registerforeventvalidation method to register the sending back or callback data for verification.

After reading the code for a long time, I did not find any problem. I checked the code again and found the ID and attribute of all the controls on the page. It was later discovered that this was the case:

Condition:
1. The screen has hidden controls.
2. Multiple gridview bindings.

3. nested use of multiple forms.
Cause:
. Net generates a _ eventvalidation hidden field in the final page based on the output element of the page. A simple test was conducted. Create a <asp: button id = "btnsubmit" runat = "server" text = "Submit" tooltip = "Submit"/> on the page, and create a corresponding click event handler. Run the program to correctly respond to events. Set btnsubmit. visable = false and manually add <input type = "Submit" name = "btnsubmit" value = "Submit"/> on the page. When you run the program, an exception containing the content of enableeventvalidation may occur. Set <@ page enableeventvalidation = "false"> and then run the program to correctly respond to the event. Observe the content of _ eventvalidation twice before and after, you can find that it is different. For exceptions, it can be considered that btnsubmit is not included in the output, but there is corresponding content when it is submitted to the background, which is inconsistent between the two sides, therefore, when event verification is enabled. net throws an exception.

Solution 1:
Page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
// Bind data;
}
}
Solution 2:
<Pages enableeventvalidation = "false"/>

1. <% @ page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. add enableeventvalidation = "false" to CS "inherits =" _ default "%>. (First)

2. Use web. config
<System. Web>
<Pages enableeventvalidation = "false"/>

3. Form nesting. A page can only have one form. You can solve this problem by checking the code carefully.

4. If the page contains controls such as dropdownlist or ListBox, the possible causes may be:

4.1 Ajax is used in the drop-down menu, which is common in the provincial/municipal linkage menu. It may be because the initial item value of the drop-down menu is assigned to the ASPX page. This error is prompted when the event is returned, delete the initial item value from the drop-down menu and add the item to the binding event.
4.2 The reason is that the value attribute of the listitem in the dropdownlist control contains Chinese characters. You only need to change the value to English or numbers. You 'd better Add the following statement to Web. config:
<Globalization requestencoding = "UTF-8" responseencoding = "UTF-8" Culture = "ZH-CN" uiculture = "ZH-CN"/> because PostBack does not use UTF-8 encoding, javascript will think there is a problem.
Only change requestencoding = "UTF-8". responseencoding = "UTF-8" is not required.

5. Register for event Validation
The principle is to let Asp.net record this PostBack value.
Registerforeventvalidation must be called at render.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.