C# 使浏览器忽略回发时的验证,即;“以前的”;
我正在使用客户端验证C# 使浏览器忽略回发时的验证,即;“以前的”;,c#,asp.net,forms,C#,Asp.net,Forms,我正在使用客户端验证 <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:TextBox runat="server" ID="Customer_Email" name="Email" type="email" required="" /> <!-- more fields -->
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:TextBox runat="server" ID="Customer_Email" name="Email" type="email" required="" />
<!-- more fields -->
<asp:Button runat="server" ID="prevbutton" Text="Previous" OnClick="prevbutton_Click" />
<asp:Button runat="server" ID="nextbutton" Text="Next" OnClick="nextbutton_Click" />
</ContentTemplate>
</asp:UpdatePanel>
按按钮,无变化;Chrome仍会提醒用户该字段是必需的
编辑2
生成的html是
<input name="ctl00$cphContentMiddleRight$Customer_Email"
id="ctl00_cphContentMiddleRight_Customer_Email"
class="form-control input-md"
type="email" required="">
<input type="submit" name="ctl00$cphContentMiddleRight$prevbutton_2"
value="Previous" id="ctl00_cphContentMiddleRight_prevbutton_2" class="btn btn-default">
我看不到任何东西告诉浏览器不要进行本机验证。设置
会导致按钮上的验证为false
<asp:Button runat="server" ID="prevbutton" Text="Previous" OnClick="prevbutton_Click" CausesValidation="false" />
不起作用;它不包含在生成的html中,因此浏览器看不到它。什么内容不包含在html中?因为我几乎可以保证,在使用aspnet验证器时,这是可行的。添加required
在所有浏览器上都不起作用,aspnet不支持这一点。切换到aspnet验证程序或创建自己的jQuery表单验证函数。我已使用自定义解决方案更新了我的答案。但是,我仍然建议使用RequiredFieldValidator
。
<asp:Button runat="server" ID="prevbutton" Text="Previous" OnClick="prevbutton_Click" CausesValidation="false" />
<asp:Button runat="server" ID="prevbutton" Text="Previous" OnClientClick="removeValidation()" />
<script type="text/javascript">
function removeValidation() {
$("#<%= Customer_Email.ClientID %>").removeAttr("required");
}
</script>