0

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;
}
GregM
  • 2,634
  • 3
  • 22
  • 37

1 Answers1

1

Yep, it's a bona fide bug. Postback fail.

Read this and this article for a fix.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
John Wu
  • 50,556
  • 8
  • 44
  • 80
  • Thanks, The only problem with those two article it's that's working fine in IE 10 , it's only when I put the compatibility mode. And the __doPostback work fine – GregM Oct 04 '13 at 23:45
  • I understand the page posts. But does the ddlFiltre_SelectedIndexChanged event fire? If not, __doPostback actually isn't working, it just looks that way. – John Wu Oct 05 '13 at 00:20
  • I really don't know if the event fire because the error is only happening when the application is on the server, when i'm developping on my pc and i'm in localhost i don't have the error – GregM Oct 05 '13 at 00:22