Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Required Field Validation In Only One Button Click

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"..

enter image description here

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>
like image 369
Surya Avatar asked Mar 22 '17 05:03

Surya


People also ask

How do I turn off required field validator?

Well you can simple use the Enabled="false" property of RequiredFieldValidator . Your markup would look something like this based on your Question.

What is enable or disable required field validator in asp net?

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.


1 Answers

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  />
like image 89
Ravi Matani Avatar answered Oct 14 '22 05:10

Ravi Matani