[英]How can I make sure that they are at least one radio been click when submit
Does anyone know how can I make sure that they are at least one radio been click when submit in C# .net? 有谁知道我如何确保在C#.net中提交时至少单击了一个广播?
I have the following code: 我有以下代码:
<asp:RadioButtonList ID="billingType" runat="server" CssClass="cl_billing_method"
RepeatDirection="Horizontal" data-messages="{required:'Billing methods is required'}">
<asp:ListItem Text="Email" Value="1"></asp:ListItem>
<asp:ListItem Text="Digital Mailbox" Value="2"></asp:ListItem>
<asp:ListItem Text="Paper" Value="0"></asp:ListItem>
</asp:RadioButtonList>
How can I validate it so that when submit button is been clicked and it will do the client check and show error if there have no radio button been selected? 我如何验证它,以便在单击“提交”按钮后,如果没有选择任何单选按钮,它将对客户端进行检查并显示错误?
<script type="text/javascript" language="javascript">
function Validate_Checkbox()
{
var chks=document.getElementsByTagName('input');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert("Please select at least one checkbox..!");
return false;
}
return true;
}
</script>
and on Submit Button you have to write 在“提交”按钮上,您必须编写
write 写
OnClientClick="return Validate_Checkbox()"
Better option is use a asp:RequiredFieldValidator
it will looks like this: 更好的选择是使用
asp:RequiredFieldValidator
它看起来像这样:
<asp:RequiredFieldValidator ErrorMessage="Billing methods is required"
ControlToValidate="billingType" runat="server" ValidationGroup="validateBill" />
Add ValidationGroup
to the button: 将
ValidationGroup
添加到按钮:
<asp:Button Text="Submit" ID="btnSubmit" runat="server" ValidationGroup="validateBill"/>
If you are getting some error saying "UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery' ..." then add the following lines to the config: 如果出现错误,提示“ UnobtrusiveValidationMode需要'jquery'使用ScriptResourceMapping ...”,则将以下几行添加到配置中:
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.