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

How to use RequiredFieldValidator for RadioButtonList in ASP.NET C#

Dear Viewers I will show how to use how to use RequiredFieldValidator for RadioButtonList in ASP.NET C#. Sometimes we want to chose at least one selection from RadioButtonList such situation RequiredFieldValidator can be easily used for validation. A submit button has been taken at the time of clicking on the submit button then a message will be displayed for warning. I have taken another reset button to clear RadioButtonList using RadioButtonList ClearSelection(); Method.

RequiredFieldValidator for RadioButtonList

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>RadioButtonList Using ReqiredFieldValidator</title>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatColumns="4" BackColor="#B4CDCD"
  ForeColor="White" BorderColor="White" BorderWidth="2"
  RepeatDirection="Horizontal" Height="100px" Width="450px">
  <asp:ListItem Value="1">Red</asp:ListItem>
  <asp:ListItem Value="2">Blue</asp:ListItem>
  <asp:ListItem Value="3">Orange</asp:ListItem>
  <asp:ListItem Value="4">Purpule</asp:ListItem>
  <asp:ListItem Value="5">Black</asp:ListItem>
  <asp:ListItem Value="6">yeollow</asp:ListItem>
  <asp:ListItem Value="7">White</asp:ListItem>
  </asp:RadioButtonList>
  <asp:RequiredFieldValidator ID="ReqiredFieldValidator1" runat="server" ControlToValidate="RadioButtonList1"
  ErrorMessage="Select your color type" ForeColor="#FF3300"></asp:RequiredFieldValidator>
 
 
  <br />
 
 
  </div>
  <asp:Button ID="btnSubmi" runat="server" Text="submit" />
  &nbsp;&nbsp;
  <asp:Button ID="btnReset" runat="server" Text="Reset" CausesValidation="False"
  onclick="btnReset_Click" />
  </form>
</body>
</html>

CODE BEHIND

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class TestDesign_RequiredFieldValidatorForRadioButtonList : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
 
  }
  protected void btnReset_Click(object sender, EventArgs e)
  {
  RadioButtonList1.ClearSelection();
  }
}

Out Put

RequiredFieldValidator-radionbuttonlist-asp.net



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