Posted by : Anwar Hossain
Category : How to use different types of validation control using asp.net c#

how to use RequiredFieldValidator in ASP.NET C#

Dear viewers hear I will show how to use RequiredFieldValidator control . sometimes we need to create must field to input data to database .Such situation JQUERY validations can be used for validation but ASP.NET has given opportunity to its required field validator which is very easy to use and understand and great client site validation control. After taking necessary textboxs we can take required field validator control beside particular textbox then ControlToValidate property need s to be used for assigning target textbox control. ErrorMessage property of RequiredFieldValidator needs to be used which message will be displayed for warning.

RequiredFieldValidator ASP.NET C#

HTML

<table style="margin-left: 0px" width="70%" cellpadding="0">
  <tr>
  <td align="right" valign="top">
  &nbsp;Name
  </td>
   <td width="10">
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtName" runat="server" Width="250px" CssClass="box17"></asp:TextBox>
  <span style="color: #CC3300">
  <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter Name"
  ControlToValidate="txtName" ForeColor="Red"></asp:RequiredFieldValidator>
  </span>
   </td>
  </tr>
  <tr>
  <td align="right" valign="middle">
  Address
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtAddress" runat="server" CssClass="box17" Height="50px" TextMode="MultiLine"
  Width="250px"></asp:TextBox>
  <span style="color: #CC3300">
  <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter Name"
  ControlToValidate="txtAddress" ForeColor="Red"></asp:RequiredFieldValidator>
  </span>
  </td>
   </tr>
  <tr>
  <td align="right" valign="middle">
  Area
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtArea" runat="server" CssClass="box17" Width="250px" Height="30px"
  TextMode="MultiLine"></asp:TextBox>
  </td>
  </tr>
  <tr>
  <td align="right" valign="middle">
  Contact
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtPhone" runat="server" Width="250px" CssClass="box17"></asp:TextBox>
  <span style="color: #CC3300">
  <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Enter Contact Info"
  ControlToValidate="txtName" ForeColor="Red"></asp:RequiredFieldValidator>
  </td>
  </tr>
  <tr>
  <td align="right" valign="middle">
  E-mail
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:TextBox ID="txtEmail" runat="server" Width="250px" CssClass="box17"></asp:TextBox>
  <span style="color: #CC3300">
  <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Enter Email Address"
  ControlToValidate="txtName" ForeColor="Red"></asp:RequiredFieldValidator>
  </span>
  </td>
  </tr>
   <tr>
  <td align="right" valign="middle">
  Enquiry
  </td>
  <td>
  &nbsp;
  </td>
  <td valign="top">
  <asp:TextBox ID="txtEnquiry" runat="server" Height="100px" TextMode="MultiLine" Width="250px"
  CssClass="box17"></asp:TextBox>
  <span style="color: #CC3300">
  <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Enter Enquiry "
  ControlToValidate="txtName" ForeColor="Red"></asp:RequiredFieldValidator>
  </span>
  </td>
  </tr>
  <tr>
   <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
  </tr>
  <tr>
  <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  <asp:Button ID="btnSend" runat="server" Text="Submit" Width="100px" />
  </td>
  </tr>
  <tr>
  <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
  <td>
  &nbsp;
  </td>
   </tr>
  </table>

Out Put

RequiredFieldValidator-asp.net.png-C#



Realted Article Headline

How to use RequiredFieldValidator for RadioButtonList in ASP.NET C#
How to use RequiredFieldValidator for DropDownList in ASP.NET C#
How to use RangeValidator in ASP.NET C#
how to use RequiredFieldValidator in ASP.NET C#
How to use RegularExpressionValidator Control in ASP.NET using C#
How to use Custom Validator control using asp.net c#
How to use compare validation control using asp.net c#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection