我正在使用必填字段验证器,它验证文本框并单击提交按钮我必须要求确认,并且我使用 java 脚本的确认()函数。问题是当我在确认框页面回发中按确定时,当我将文本框留空时,必填字段验证器不会停止页面。从 stackoverflow 阅读帖子后,我使用自定义验证器来停止页面,但我不能这里是代码。
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" ValidationGroup="one" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="one"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="validate();" ValidationGroup="one" onclick="Button1_Click"/>
<asp:CustomValidator ID="CustomValidator1" ValidateEmptyText="true" runat="server" ValidationGroup="one" ErrorMessage="CustomValidator"></asp:CustomValidator>
<script type='text/javascript'>
function validate() {
var cv = document.getElementById('MainContent_CustomValidator1');
if (cv) {
cv.isValid = confirm('are you sure want to update record ?');
}
} </script>