.net dropDownList losing value after postback in IE
I have a problem with the selected value of a dropDown.
The code working perfectly fine, except when I change the IE compatibility mode, the drop down don't keep the selected value and come back to the first item and i can't make it work anymore.
When I change something on the server, files or configuration in IIS, everything is working fine until I Change de compatibility mode again.
I've tried putting the selected value in the session to keep it but it's not working. I really tried everything, thanks in advance.
here's the asp code :
<asp:DropDownList ID="ddlFiltre" runat="server" AutoPostBack="True" EnableViewState="true" Width="100%" OnSelectedIndexChanged="ddlFiltre_SelectedIndexChanged">
</asp:DropDownList>
Here's the code behind:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ddlFiltre.Items.Clear();
ddlFiltre.Items.Add(new ListItem(GetLibelle("item1"), "-1"));
ddlFiltre.Items.Add(new ListItem(GetLibelle("item2"), "0"));
ddlFiltre.Items.Add(new ListItem(GetLibelle("item3"), "1"));
ddlFiltre.Items.Add(new ListItem(GetLibelle("item4"), "2"));
GetPermission();
}
else
{
ddlFiltre.SelectedValue = Session["ddl_index"].ToString();
}
LoadPageControls();
}
private void GetPermission()
{
}
private void LoadPageControls()
{
if (LoggedUser != null)
{
if (ddlFiltre.SelectedValue == "-1")
{
// Load info in table
}
else
{
// Load other info in table
}
}
}
protected void ddlFiltre_SelectedIndexChanged(object sender, EventArgs e)
{
Session["ddl_index"] = ddlFiltre.SelectedValue;
}
Yep, it's a bone fide bug. Postback fail.
Read this and this article for a fix.
链接地址: http://www.djcxy.com/p/67238.html上一篇: 什么是不可思议的数字错误?