关于单选按钮验证 [英] regarding radio button validation

查看:128
本文介绍了关于单选按钮验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对单选按钮验证存在问题.我想使用当我单击提交"按钮而不选择任何一个单选按钮时发生的验证.就像会有两个单选按钮,其中包含文本(男,女).
当我选择男性时,验证将被隐藏,而当我选择两者都不选择时,验证将可见(验证错误应在标签中).

i have a problem with radiobutton validation . i want to use such a validation that occur when i click on submit button without selecting any one of radiobutton. like there will be two radio button that contains the text like(male, female).
and when i select male the validation would be hide and when i select none of these two then validation will be visible(validation error should be in label).

推荐答案

在单选按钮的GroupName属性中添加相同的名称
Just add the same name in radiobutton GroupName property


使此代码单击按钮单击事件

if(Radiobutton1.checked!= true && Radiobutton2.checked!= true)
{
label1.text =请选择性别";
}

我认为这段代码确实可以帮助您

问候

:)
Wright this codeon button click event

if(Radiobutton1.checked !=true && Radiobutton2.checked !=true)
{
label1.text="Plz select Gender";
}

i think this code realy help u

Regard
Sham
:)


1.添加GroupName属性,并为两个单选按钮添加相同的值.
例如:GroupName ="Gender"
2.放入所需的字段验证器.

您可以使用RadioButtonList进行相同的操作,如下所示:

< asp:radiobuttonlist runat ="server" id ="radio" xmlns:asp =#unknown">
<%-隐含在单选按钮列表中显示的项目-%>
< asp:listitem value ="0"> Male
< asp:listitem value ="1">女性

<%-创建RequiredFieldValidator控件以验证我们创建的RadioButtonList-%>


< asp:requiredfieldvalidator runat ="server" id ="radRfv" controltovalidate ="radio" initialvalue ="0" errormessage =选择一个选项" xmlns:asp =#unknown">

希望对您有帮助

〜Amol
1. Add GroupName attribute and put same value for both the radio buttons.
for example: GroupName="Gender"
2. Put required field validator.

You can do the same using RadioButtonList as follows:

<asp:radiobuttonlist runat="server" id="radio" xmlns:asp="#unknown">
<%--Creaint Items to be display in Radio Button List--%>
<asp:listitem value="0">Male
<asp:listitem value="1">Female

<%--Creating RequiredFieldValidator control to validate RadioButtonList that we have created--%>


<asp:requiredfieldvalidator runat="server" id="radRfv" controltovalidate="radio" initialvalue="0" errormessage="Select one option" xmlns:asp="#unknown">

Hope this will help you

~Amol


这篇关于关于单选按钮验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆