我有以下 asp.net 代码:
<script type="text/javascript">
$(document).ready(function () {$(".button").click(function (event) {
alert("Button pressed!");
});
});
</script>
<asp:Button ID="button" runat="server" CssClass="button" />
<asp:UpdatePanel ID="testUpdatePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="testTextBox" EventName="TextChanged" />
</Triggers>
<ContentTemplate>
<asp:TextBox ID="testTextBox" runat="server" AutoPostBack="true" CausesValidation="true" ValidationGroup="test" CssClass="Test" />
<asp:RegularExpressionValidator ID="testRegularExpressionValidator" runat="server" ControlToValidate="testTextBox" ErrorMessage="*2" ValidationExpression="(19|20)\d\d\-(0[1-9]|1[012])\-([012][0-9]|3[01])" ValidationGroup="test" />
<asp:Label ID="testLabel" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
以及以下代码隐藏:
Private Sub testTextBox_TextChanged(sender As Object, e As System.EventArgs) Handles testTextBox.TextChanged
If (Not Page.IsValid) Then
Return
End If
testLabel.Text = testTextBox.Text
End Sub
如果我在 FF(v15,v15.0.1) 中运行它,在文本框中输入 1987-05-03 然后按回车键,它会触发按钮,之后我会回发到 testTextBox_TextChanged,当它击中他的行If (Not Page.IsValid)
然后我得到以下例外:
Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate.
如果我在 IE 中做同样的事情,按钮永远不会被触发,我也不例外!那么,为什么 FF 会出现这样的行为不端呢?我没有在我的任何面板上设置 DefaultButton..