Asp.net RequiredFieldValidator validate to RadioButtonList
Asp.net RequiredFieldValidator(how to validate RadioButtonList):
In this article we learn how to validate a RadioButtonList using
JavaScript in ASP.NET. As we know that JavaScript provides a way to validate a web
page’s data on the client's computer before sending it to the web server.
Other Radiobuttonlist related example in asp.net:
- How To bind RadioButtonList Control From data base
- Access RadioButtonList Item Using VBScript
- Use radiobuttonlist with VB
- Example of jQuery Validate on Radiobuttonlist in Asp.Net using C#
- Example of RadioButtonList control.
- Html Radio Button
- ASP.NET RadioButton Control
- Hide radio buttons in JavaScript on button click.
To validate RadioButtonList in JavaScript:
function getCheckedRadioButton()
{
var radio = document.getElementsByName("RadioButtonList1");
for (var i = 0; i < radio.length; i++)
{
if (radio[i].checked) {
alert("Radio button
having value " + radio[i].value + " was checked."); // Show the checked value
return true;
}
}
alert("Not checked any radio button");
}
Validating RadioButtonList:
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="Radiobuttonlist_validation.aspx.cs"
Inherits="Radiobuttonlist_validation"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void
Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Select one : ";
Label1.Text += RadioButtonList1.SelectedItem.Text.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net RequiredFieldValidator example: how to
validate RadioButtonList</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color: Green">
RadioButtonList Validation in asp.net using C#</h2>
<asp:Label ID="Label1" runat="server"
Font-Size="Large"
ForeColor="Red">
</asp:Label>
<br />
<br />
<asp:RadioButtonList ID="RadioButtonList1"
runat="server"
RepeatColumns="3"
ForeColor="Black"
BorderColor="DarkBlue"
BorderWidth="2">
<asp:ListItem>CheckBoxList</asp:ListItem>
<asp:ListItem>TreeView</asp:ListItem>
<asp:ListItem>Button</asp:ListItem>
<asp:ListItem>SqlDataSource</asp:ListItem>
<asp:ListItem>GridView</asp:ListItem>
<asp:ListItem>Calendar</asp:ListItem>
<asp:ListItem>BulletedList</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator
ID="ReqiredFieldValidator1"
runat="server"
ControlToValidate="RadioButtonList1"
ErrorMessage="Select
your favorite!">
</asp:RequiredFieldValidator>
<br />
<asp:Button ID="Button1"
runat="server"
ForeColor="Red"
Text="Submit
"
OnClick="Button1_Click"
Width="165px"
/>
</div>
</form>
</body>
</html>
Other asp.net related Post:
- Display selected Date from data base into asp.net calendar
- How to Make a HTML Table by C# code in asp.net programming
- How to Calculate Number of Sunday in a particular month by asp.net programming.
- How to Print Div in Asp.net Programming by javaScript
- How to Make Data Table By C# code in Asp.net Programming:
- how to add capcha in Asp.net programming
- Example of Crystal report(Crystal_report_in asp.net programming )
- How To bind RadioButtonList Control From data base
- Access RadioButtonList Item Using VBScript
- Use radiobuttonlist with VB
- Example of RadioButtonList control.
- Html Radio Button
- ASP.NET RadioButton Control
- Hide radio buttons in JavaScript on button click
Comments
Post a Comment