代码之家  ›  专栏  ›  技术社区  ›  Tom

提交时asp.net CompareValidator未按预期运行

  •  0
  • Tom  · 技术社区  · 14 年前

    这是密码。

    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>
    

    有什么想法吗?

    2 回复  |  直到 14 年前
        1
  •  2
  •   Frédéric Hamidi    14 年前

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

    Sub myGo(sender As Object, e As EventArgs)
        If Page.IsValid Then
            Response.Redirect("http://www.google.co.uk")
        End If
    End Sub
    
        2
  •  0
  •   Arief    14 年前

    使用ValidationGroup=“…..”