I used Asp.net to develop a website and added an ASP: dropdownlist control and an ASP: button to a page. added a click event onclick button to ASP: button, when the webpage call is normal, the following error message is displayed when ASP: dropdownlist control data is bound and the button is clicked again:
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.
Solution:
1. Add<% @ Page enableeventvalidation = "false" %> however, Your webpage security may be affected.
2. Use clientscriptmanager again as prompted. registerforeventvalidation solves the problem and finds the cause. I used the dropdownlist control on the webpage to add data to the control. The content of the original control is empty, so it has no effect on verification, however, to add more data, visual studio2005 needs to verify the added data, which can be seen from the source code of the webpage, <input type = "hidden" name = "_ eventvalidation" id = "_ eventvalidation" value = ""> the values in this hidden control are different. This is because of ASP. Net will traverse all the items in the dropdownlist when generating the client script. These values are then PostBack to the server. Therefore, the values of these items must be recorded and put into the page. That is, the value in the hidden control just mentioned. So how can we use clientscriptmanager. registerforeventvalidation to solve this problem ??
Solution:
You only need to override the protected override void render (htmltextwriter writer) function, and traverse the items in the dropdownlist control in the function. Register each item to the client.
Protected override void render (htmltextwriter writer)
{
Foreach (listitem in dropcpdw. Items)
{
Clientscript. registerforeventvalidation (dropcpdw. uniqueid, listitem. value );
}
Base. Render (writer );
}