CustomValidator in UpdatePanel working oddly in IE9

I have a CustomValidator that is inside of a Wizard control which is inside of an UpdatePanel .

Without the UpdatePanel , everything works as expected, but things get odd in IE9 only once the UpdatePanel is added.

Inside a step of the wizard, I have a GridView that is populated via a search and all of that works fine.

<asp:CustomValidator ID="cvSelectedUser" runat="server"
    CssClass="Validator"
    ErrorMessage="You must select a user to alter before you may continue"
    OnServerValidate="cvSelectedUser_ServerValidate">
</asp:CustomValidator>

<asp:Panel ID="pSearchExisting" runat="server"
    Height="120px"
    ScrollBars="Vertical">
    <asp:GridView ID="gvSearchExisting" runat="server"
        AutoGenerateColumns="false"
        DataKeyNames="UniqueID"
        EmptyDataText="No users found from your search."
        Width="95%">
        <AlternatingRowStyle CssClass="GridViewAlternatingRow" />
        <HeaderStyle CssClass="GridViewHeader" />
        <SelectedRowStyle CssClass="GridViewSelectedRow" />
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" SortExpression="EmployeeID" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="UserID" HeaderText="User ID" SortExpression="UserID" />
        </Columns>
    </asp:GridView>
</asp:Panel>

The CustomValidator is used to make sure the user selected a search result before continuing and only prevents the user from going to the next wizard step if they don't.

protected void cvSelectedUser_ServerValidate(object sender, ServerValidateEventArgs e)
{
    e.IsValid = true;
    if (gvSearchExisting.SelectedIndex == -1)
        e.IsValid = false;
}

This is confirmed in the wizard events.

protected void wUserID_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
    if (Page.IsValid == false)
        return;

    // process navigation
}

The odd thing that happens in IE9 (only) is that if you click the Next button on the wizard and you didn't select a record from the GridView , it prevents you from going to the next step, but the CustomValidator error message isn't displayed.

The user can keep hitting next and the error message doesn't display. However, oddly, if you click on the page, losing the focus of the Next button and then click the Next button again, it will display the error message.

To make it more troubling, this works as expected in Chrome, Firefox, IE8, etc. Just not IE9.

As a recap

Error message does not display in IE9

  • Don't select a user
  • Click the Next button as many times as you want
  • No message displayed
  • Error message does display in IE9

  • Don't select a user
  • Click the Next button
  • Unfocus the Next button (Click someplace else on the page, like the white space on the background)
  • Click the Next button again
  • The message is displayed
  • Any idea on how to fix this?

    I did find a work-around that seems like a hack via https://stackoverflow.com/a/12926317/935779. This just forces IE9 into compatibility mode. I would much rather a proper fix.

    <meta http-equiv="X-UA-Compatible" content="IE=IE8" />
    
    链接地址: http://www.djcxy.com/p/36526.html

    上一篇: 在ie8 / 9中忽略CSV文件下载

    下一篇: UpdatePanel中的CustomValidator奇怪地在IE9中工作