Why can't I get the correct value of selectedindex of dropdownlist on the server after updatepanel is used?

Source: Internet
Author: User
Find out why the server cannot obtain the correct value of selectedindex of dropdownlist after updatepanel is used;
After trying various methods, the problem was finally solved. The final problem is that the following configuration items are configured in Web. config:
<System. Web>
<Globalization requestencoding = "gb2312" responseencoding = "gb2312"/>
</System. Web>
After canceling the configuration item;
In the first place, I thought the problem should be on updatepanel or masterpage. So I took some steps to troubleshoot the problem one by one:
1. Create a new page on which masterpage is used for the analysis_report.aspx page;
2. Add a dropdownlist on this page with the following content:
<Asp: dropdownlist id = "dropdownlist1" runat = "server">
<Asp: listitem> 111 </ASP: listitem>
<Asp: listitem> 222 </ASP: listitem>
</ASP: dropdownlist>
Add a button and a label to the server side of the button. Code As follows:
Protected void button#click (Object sender, eventargs E)
{
Label1.text = dropdownlist1.selectedindex. tostring ();
}
After verification, everything is normal;
3. Add an updatepanel on the page, and move the previous three controls: dropdownlist, button, and label to the updatepanel. Run again Program , After verification, everything is normal;
4. Considering that the items in dropdownlist in analysis_report.aspx use Chinese, all the definitions of dropdownlist on this test page are changed:
<Asp: dropdownlist id = "dropdownlist1" runat = "server">
<Asp: listitem> China </ASP: listitem>
<Asp: listitem> Japan </ASP: listitem>
</ASP: dropdownlist>
After running the program, click the button to bring up a prompt dialog box
Invalid PostBack or ........
This prompt box appears the same as in analysis_report.aspx. It is easy to delete this dialog box. You only need to add enableeventvalidation = "false" to the <% @ Page %> tab of the page header;
In this way, the prompt dialog box does not appear, but after clicking the button, no matter which option is selected, the displayed value in label1 is always 0, that is, the correct selecteindex cannot be obtained;
5. Is dropdownlist in updatepanel unable to use Chinese Characters? It should not be so mentally retarded, so I decided to try it in another project. So I created a new site that supports Ajax, copy the masterpage used in the previous article, and then copy the previous test page. After the verification is run, everything is normal; the correct selectedindex can be obtained;
6. The test pages in the two projects are the same. Now I think the difference may be the configuration file. Compare the configuration files in the two projects and find the web in pqsys2. config has the following configuration items:
<System. Web>
<Globalization requestencoding = "gb2312" responseencoding = "gb2312"/>
</System. Web>
Set <globalization requestencoding = "gb2312" responseencoding = "gb2312"/>
After deletion, run the test page in the pqsys2 project. Everything is normal;

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.