我的页面由html5输入和asp网格视图组成。当我尝试按任意行上的网格视图按钮时,将显示HTML5输入验证消息。我不能使用网格asp按钮而不填写表单的必填字段,但我不需要填写表格以使用网格视图。
我希望HTML5输入验证仅适用于提交按钮,而不适用于页面中的所有按钮。我怎么能这样做?
<div class="content">
<div class="box box-default">
<div class="form-horizontal">
<div class="form-group">
<label class="col-md-2 control-label">Type</label>
<div class="col-md-4">
<input type="text" class="form-control input_text" runat="server" id="inputType" placeholder="BILLING TYPE" required="required" autocomplete="off" />
</div>
<div class="col-md-4">
<asp:RequiredFieldValidator ID="rfv2" ControlToValidate="inputType" ErrorMessage="*" ValidationGroup="btnSubmitClick" runat="server"></asp:RequiredFieldValidator>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Amount</label>
<div class="col-md-4">
<input type="number" class="form-control input_text" runat="server" id="inputAmount" placeholder="BILLING AMOUNT" required="required" autocomplete="off" />
</div>
<div class="col-md-4">
<asp:RequiredFieldValidator ID="rfv3" ControlToValidate="inputAmount" ErrorMessage="*" ValidationGroup="btnSubmitClick" runat="server"></asp:RequiredFieldValidator>
</div>
</div>
<div class="form-group">
<div class="col-md-2"></div>
<div class="col-md-2">
<asp:Button ID="btnSubmit" runat="server" Text="SUBMIT" OnClick="btnSubmit_Click" Style="width: 100%" class="btn btn-block btn-primary"
CausesValidation="true"
ValidationGroup="btnSubmitClick"
OnClientClick="if (!Page_ClientValidate()){ return false; } this.disabled = true; this.value = 'Saving...';"
UseSubmitBehavior="false" />
</div>
</div>
</div>
</div>
<div class="col-md-12">
<asp:ScriptManager ID="adminScriptManager" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<div id="div_grid" runat="server">
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="false"
Width="100%"
HeaderStyle-HorizontalAlign="Left"
CssClass="gridview"
AlternatingRowStyle-CssClass="even" DataKeyNames="ID" OnRowCommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField HeaderText="S No." ItemStyle-Width="5%">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="BILLING_AMOUNT"
HeaderText="AMOUNT">
<ItemStyle VerticalAlign="Top" />
</asp:BoundField>
<asp:BoundField DataField="CREATED_BY"
HeaderText="CREATED BY">
<ItemStyle VerticalAlign="Top" />
</asp:BoundField>
<asp:TemplateField HeaderText="STATUS">
<ItemTemplate>
<asp:Button ID="btnBilled" CommandName="ChangeStatus" CommandArgument='<%#Eval("ID")+","+ Eval("BILL_STATUS")%>' Text='<%# Convert.ToBoolean(Eval("BILL_STATUS")) ? "DISABLE" : "ENABLE" %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
</div>
当我在网格视图中按下asp Button ID =“btnBilled”时,会显示输入字段inputType的html5验证。我怎么能绕过这个?
答案 0 :(得分:0)
CausesValidation
用于验证asp.net验证器而非HTML5验证。
我使用了属性formnovalidate="formnovalidate"
<asp:Button ID="btnBilled" CommandName="ChangeStatus" formnovalidate="formnovalidate" CommandArgument='<%#Eval("ID")+","+ Eval("BILL_STATUS")%>' Text='<%# Convert.ToBoolean(Eval("BILL_STATUS")) ? "DISABLE" : "ENABLE" %>' runat="server"
CausesValidation="false" />
有效。
答案 1 :(得分:-1)
设置CausesValidation =&#34; false&#34;在按钮上:
<asp:Button ID="btnBilled" CommandName="ChangeStatus" CommandArgument='<%#Eval("ID")+","+ Eval("BILL_STATUS")%>' Text='<%# Convert.ToBoolean(Eval("BILL_STATUS")) ? "DISABLE" : "ENABLE" %>' runat="server"
CausesValidation="false" />