In ASP. NET, the callback or callback parameters are invalid.

Source: Internet
Author: User

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 );
}

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.