我有以下的asp.net代碼:asp.net的UpdatePanel和Firefox Page.IsValid導致異常
<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上我的任何面板..
如果你看我的asp.net,你會看到CausesValidation設置爲true在文本框.. – Peter