Solve the Problem of cascadingdropdown sending or callback parameters of ASP. NET Ajax application being invalid
In this example, the cascade drop-down effect is displayed, and the problem of "sending back or callback parameter invalid" occurs. Based on the introduction on the Internet and your own test, let's talk about the following:
Page aspx
Code
<Tr>
<TD align = "right" style = "height: 50px; width: 300px;">
Department
</TD>
<TD align = "Left" style = "height: 50px">
& Nbsp;
<Asp: dropdownlist id = "department" runat = "server">
</ASP: dropdownlist>
<PC3: cascadingdropdown id = "cascadingdropdown1" runat = "server" Category = "Province"
Loadingtext = "loading..." prompttext = "Please choose Department" servicemethod = "getdropdowncontents" targetcontrolid = "department"
Servicepath = "WebService. asmx">
</PC3: cascadingdropdown>
</TD>
</Tr>
<Tr>
<TD align = "right" style = "height: 50px; width: 300px;">
Class
</TD>
<TD align = "Left" style = "height: 50px">
& Nbsp;
<Asp: dropdownlist id = "class" runat = "server" onselectedindexchanged = "class_selectedindexchanged"
Autopostback = "true">
</ASP: dropdownlist>
& Nbsp;
<PC3: cascadingdropdown id = "cascadingdropdown2" runat = "server" Category = "city" loadingtext = "loading ..."
Prompttext = "select class" servicemethod = "getdropdowncontents" targetcontrolid = "class"
Servicepath = "WebService. asmx" parentcontrolid = "department">
</PC3: cascadingdropdown>
</TD>
</Tr>
Possible problems:
The callback parameter is invalid. Use <pages enableeventvalidation = "true"/> in configuration or on the page
<% @ Page enableeventvalidation = "true" %>
Event verification is enabled. 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 registers sending back or callback data for verification.
English description
Id PostBack or callback argument. Event validation is enabled using
<Pages enableeventvalidation = "true"/> in configuration or <% @
Page enableeventvalidation = "true" %> in a page. For security
Purposes, this feature verifies that arguments to PostBack or callback
Events originate from the server control that originally rendered them.
If the data is valid and expected, use
Clientscriptmanager. registerforeventvalidation method in order
Register the PostBack or callback data for valida
Feasible solutions include:
1. <% @ page Language = "C #" autoeventwireup = "true" on the page"
Codefile = "default. aspx. cs" inherits = "_ default" %> Add
Enableeventvalidation = "false. (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.
Protected override void render (htmltextwriter writer)
{
Clientscript. registerforeventvalidation (_ recipelist. uniqueid, "4 ");
Base. Render (writer );
}
If we write a control by ourselves and use the validate events function, we need to use supportseventvalidation attribute,
[supportseventvalidation]
public class dynamicdropdownlist: dropdownlist
{< br> protected override void render (system. web. UI. htmltextwriter writer)
{< br> page. clientscript. registerforeventvalidation (this. uniqueid, "4");
base. render (writer);
}< BR >}