i am developing application in asp.net c#, in that i have a problem . the problem is i have three fields in a asp.net page, in that it having Bank Name, Branch, and IFSC Code, these three is mandatory to fill when i click save button,
but when i click search & clear button also it should ask to fill these fields. how to restrict this when click other buttons
"please fill in this field"..
suppose if i search sbi bank only, it asks to enter every field.
MY CODE Enter Bank
</div>
<div class="form-group col-md-3">
<label for="exampleInputEmail1">
Enter Branch</label>
<asp:TextBox ID="txtBranchName" runat="server" type="text" CssClass="form-control" PlaceHolder="Enter Branch" required />
</div>
<div class="form-group col-md-3">
<label for="exampleInputEmail1">
Enter IFSC Code</label>
<asp:TextBox ID="txtIFSCCode" runat="server" type="text" CssClass="form-control" PlaceHolder="Enter IFSC Code" required />
</div>
</td>
</tr>
</table>
<br />
<br />
<table border="0px" cellpadding="4px" cellspacing="4px" align="center" width="180px">
<tr>
<td>
<asp:Button ID="btnSave" runat="server" ValidationGroup="valInsert" Text="Save" OnClick="btnSave_Click" ToolTip="Save" CssClass="btn btn-success" />
</td>
<td>
<asp:Button ID="btnClear" runat="server" Text="Clear" OnClick="btnClear_Click" ToolTip="Clear / Refresh" CssClass="btn btn-default" />
</td>
<td>
<asp:Button ID="btnSearch" runat="server" ValidationGroup="valInsert" Text="Search" OnClick="btnSearch_Click" ToolTip="Search" CssClass="btn btn-success" /></td>
<td>
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="return PrintPanel();" ToolTip="Print" CssClass="btn btn-default" />
</td>
</tr>
</table>
Well you can simple use the Enabled="false" property of RequiredFieldValidator . Your markup would look something like this based on your Question.
Use ValidatorEnable function from the Asp.net javacsript Script Library to Enable/Disable the validators on client side. Sometimes you may need to enable/disable validators on client side. you can easily do this using ValidatorEnable function in the Asp.net javacsript Script Library.
Try to put formnovalidate
in your search button code
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" ToolTip="Search" CssClass="btn btn-success" formnovalidate />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With