• 在使用了UpdatePanel后,在服务器端为什么无法得到DropDownList的SelectedIndex的正确值


    弄清为什么在使用了UpdatePanel后,在服务器端为什么无法得到DropDownList的SelectedIndex的正确值;
    在尝试了各种方法之后,问题终于得到解决。最终的问题在于web.config配置了如下的配置项:
    <system.web>
      <globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
    </system.web>
    在把该配置项取消了之后就好了;
    一开始认为问题应该就出在UpdatePanel或者是MasterPage上;于是就按照一定的步骤来逐个排除原因:
    1、新建一个页面,在这个页面中使用了Analysis_Report.aspx页面使用的masterpage;
    2、在这个页面中添加一个DropDownList,内容如下:
    <asp:DropDownList id="DropDownList1" runat="server">
        <asp:ListItem>111</asp:ListItem>
        <asp:ListItem>222</asp:ListItem>
    </asp:DropDownList>
    再添加一个button和一个label,button的服务器端代码如下:
    protected void Button1_Click(object sender, EventArgs e)
    {  
    Label1.Text = DropDownList1.SelectedIndex.ToString();
    }
    经过验证,一切正常;
    3、在页面上添加一个updatepanel,把前面的DropDownList,button,label三个控件都移到UpdatePanel内部。再次运行程序,经过验证,一切正常;
    4、考虑到在Analysis_Report.aspx中的DropDownList中的项使用的是中文,所有把这个测试页面中的DropDownList的定义改为:
    <asp:DropDownList id="DropDownList1" runat="server">
        <asp:ListItem>中国</asp:ListItem>
        <asp:ListItem>日本</asp:ListItem>
    </asp:DropDownList>
    运行程序之后,点击按钮时,弹出提示对话框
    invalid postback or ........
    这个提示框和在Analysis_Report.aspx中出现的一样。消除这个对话框是比较容易的,只要在页头的<%@ Page  %> 标签内添加 EnableEventValidation="false" 即可;
    这样虽然提示对话框不会出现,但是在点击按钮之后,不管选择的是哪一项,Label1中显示的一直都是0,也就是无法得到正确的Selecteindex;
    5、难道是在UpdatePanel中的DropDownList就不能使用中文,应该不会这么弱智吧,于是决定在另外一个工程中试试;于是新建一个支持ajax的站点,将上文中使用的masterpage拷贝过去,然后再把上面的那个测试页面也拷贝过去。运行验证之后,发现一切正常;能够得到正确的selectedindex;
    6、两个工程中的测试页面是相同的,现在觉得不同的地方可能就是配置文件了,将两个工程中的配置文件一对比,发现在PQsys2的web.config中有如下配置项:
    <system.web>
      <globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
    </system.web>
    把这个<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
    删除之后,再运行pqsys2工程中的那个测试页面,一切正常;
  • 相关阅读:
    模式使用详解 手拉手就是职责链吗?
    简单说两句味道
    胡说两句...
    补充说明: 表驱动, 链表与职责链
    C++/CLI和TMP: enum hack相當於static const int吗?
    WCF NetTcpBinding Transport安全模式(9) ClientCredentialType证书验证模式Custom验证模式
    WCF NetTcpBinding Transport安全模式(8) ClientCredentialType证书验证模式 PeerOrChainTrust验证模式
    WCF NetTcpBinding Transport安全模式(2) 默认安全配置
    WCF NetTcpBinding Transport安全模式(7) ClientCredentialType证书验证模式 ChainTrust验证模式
    WCF NetTcpBinding Transport安全模式(6) ClientCredentialType证书验证模式 PeerTrust验证模式
  • 原文地址:https://www.cnblogs.com/strinkbug/p/592443.html
Copyright © 2020-2023  润新知