0

I'm not the first to complain about OnSelectedIndexChanged not firing in IE, once deployed:

Here's my code:

<asp:DropDownList id="MyDropDownList" runat="server">
    <asp:ListItem Text="Life" Value="1" />
    <asp:ListItem Text="Universe" Value="2" />
    <asp:ListItem Text="Everything" Value="42" />
</asp:DropDownList >

and:

protected override void OnInit(EventArgs e)
{
    MyDropDownList.AutoPostBack = true;
    MyDropDownList.SelectedIndexChanged += new EventHandler(MyDropDownList_SelectedIndexChanged);
}

protected void MyDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
  //lots of cool stuff
}

Now let us dig into the result HTML.

Here's with Chrome, (or IE with compatibility mode):

<select name="MyDropDownList" onchange="javascript:setTimeout('__doPostBack(...)', 0)" id="MyDropDownList">
    <option value="1" selected="selected">Life</option>
    <option value="2">Universe</option>
    <option value="42">Everything</option>
</select>

And here it is with IE10/IE11 (without compatibility):

<select name="MyDropDownList" id="MyDropDownList">
    <option value="1" selected="selected">Life</option>
    <option value="2">Universe</option>
    <option value="42">Everything</option>
</select>

Surprise!
The onchange attribute is gone!

OK...
So now I know why the event isn't firing from IE.
...But why is it rendered differently?

Important detail: This only happens once deployed to server (I believe it's IIS6). Locally, it works fine.

Another important detail: Installing any sort of patch is unfortunately not an option for me.

Community
  • 1
  • 1
Yehuda Shapira
  • 8,460
  • 5
  • 44
  • 66

2 Answers2

0

why don't you do this :

<asp:DropDownList id="MyDropDownList" runat="server" AutoPostBack="true" onSelectedIndexChanged="MyDropDownList_SelectedIndexChanged"   >
<asp:ListItem Text="Life" Value="1" />
<asp:ListItem Text="Universe" Value="2" />
<asp:ListItem Text="Everything" Value="42" />
</asp:DropDownList >

and on server side :

protected void MyDropDownList_SelectedIndexChanged(object sender,EventArgs e)
{
  //do stuff here
}
Sora
  • 2,465
  • 18
  • 73
  • 146
  • Truth is, I just posted my code as-is. Your code IS cleaner, but doesn't solve the problem. Do you think I should neaten it up HERE, just to make it more readable? – Yehuda Shapira Feb 18 '14 at 09:41
  • i mean why you are adjusting an event handler from the code behind using the onInit and you have the ability to do it from the client side ? maybe the onInit function defer from IE and Firefox – Sora Feb 18 '14 at 10:14
  • OnInit happens on the server. Why would it be different for different browsers? – Yehuda Shapira Feb 18 '14 at 10:17
0

Turns out it's a known issue, with fixes:
Scott Hanselman - bug in the browser definition files

There is a bug in the browser definition files that shipped with .NET 2.0 and .NET 4, namely that they contain definitions for a certain range of browser versions. But the versions for some browsers (like IE 10) aren't within those ranges any more. Therefore, ASP.NET sees them as unknown browsers and defaults to a down-level definition, which has certain inconveniences, like that it does not support features like JavaScript.

The fixes are either
1. Update server's .NET (good idea)
2. Add appropriate ie.browser (can be found here or here) to App_browsers folder (workaround in case first option isn't available.)

Community
  • 1
  • 1
Yehuda Shapira
  • 8,460
  • 5
  • 44
  • 66