asp.net CompareValidator 在提交时未按预期运行
我正在尝试让 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>
?
I'm trying to get a CompareValidator to work but having a few problems. If the submit button does not run a function it works fine, but the validator does not work if there is a function attached to the button.
Here's the code.
Sub myGo(sender As Object, e As EventArgs)
response.redirect("http://www.google.co.uk")
End Sub
and
<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>
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
验证器应该可以正常工作,但您可能应该仅在页面有效时才执行重定向:
The validator should work fine, but you probably ought to perform the redirect only if the page is valid:
使用 ValidationGroup="...."
Use ValidationGroup="...."