0

我正在尝试让 CompareValidator 工作,但遇到了一些问题。如果提交按钮没有运行某个功能,它可以正常工作,但如果按钮附加了一个功能,则验证器将无法工作。

这是代码。

Sub myGo(sender As Object, e As EventArgs)
    response.redirect("http://www.google.co.uk")
End Sub

<form runat="server">
<asp:TextBox id="txt1" runat="server" /> = <asp:TextBox id="txt2" runat="server" /> <asp:Button OnClick="myGo" Text="not working with onclick" runat="server" /> <asp:Button Text="working button" runat="server" />
<br />
<asp:CompareValidator EnableClientScript="false" id="compval" Display="dynamic" ControlToValidate="txt1" ControlToCompare="txt2" Type="String" Text="Validation Failed!" runat="server" />
</form>

有任何想法吗?

4

2 回答 2

2

验证器应该可以正常工作,但您可能应该仅在页面有效时执行重定向:

Sub myGo(sender As Object, e As EventArgs)
    If Page.IsValid Then
        Response.Redirect("http://www.google.co.uk")
    End If
End Sub
于 2010-11-09T14:21:12.533 回答
0

使用 ValidationGroup="...."

于 2010-11-09T14:40:10.097 回答