我如何验证复选框? [英] How can i validate check box?
问题描述
我想验证项目中的复选框。 I want to validate checkbox in my project. 这篇关于我如何验证复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
使用以下代码,
< pre lang =c#> protected void buttonOk_Click( object sender,EventArgs e)
{
if (!chkbox.Checked)
{
buttonOkk。 Attributes.Add( OnClick,
javascript:return chkbox());
}
else
{
Response.Redirect(xxxxx, false 跨度>);
}
}
< head id = Head1 runat = server >
< title > xxxx Page < / title >
< script type = text / javascript >
function checkCheckBoxes()
{
alert('Please check' );
}
< / script >
< / head >
但是我在我的页面中运行代码,当我第一次检查而没有选中复选框时它没有显示警报。但是第二次当我这样做时会收到警报。
我收到两个案例的警报信息(已检查) /未选中)。我只想在未选中复选框的情况下显示提醒。
请快速告诉我解决方案。
如果您有任何好主意,请分享。
我可以使用c#代码显示错误消息吗?您好Kavitha,
如果可以在你的项目中使用jQuery,然后请查看下面的链接。
http://jsfiddle.net/M9dXx / [ ^ ]
谢谢,
Vamsi
http://stackoverflow.com/questions/4436524/how-to-validate-for-checkbox -selection-if-all-checkbox-have-same-name [ ^ ]
http://www.chennaisunday.com/jscheckbox.html [ ^ ]
http ://jesin.tk/javascript-validation-textbox-combobox-radiobutton-checkbox/ [ ^ ]
你可以尝试使用javascript ..检查这个链接..可能你会得到帮助......
Am using following code,
protected void buttonOk_Click(object sender, EventArgs e)
{
if (!chkbox.Checked)
{
buttonOkk.Attributes.Add("OnClick",
"javascript:return chkbox()");
}
else
{
Response.Redirect(xxxxx, false);
}
}
<head id="Head1" runat="server">
<title>xxxx Page</title>
<script type="text/javascript">
function checkCheckBoxes()
{
alert ('Please check');
}
</script>
</head>
but while am running the code in my page when i check first time without checking check box it is not showing alert.But second time when i do same am getting alert.
Am getting alert message for both case (Checked/unchecked). I want to show alert only if checkbox is unchecked.
please let me know the solution fast.
please share if you have any good ideas.
Can i show error message using c# code?Hi Kavitha,
If you can use jQuery in you project, then please look into the below link for example.
http://jsfiddle.net/M9dXx/[^]
Thank you,
Vamsihttp://stackoverflow.com/questions/4436524/how-to-validate-for-checkbox-selection-if-all-checkbox-have-same-name[^]
http://www.chennaisunday.com/jscheckbox.html[^]
http://jesin.tk/javascript-validation-textbox-combobox-radiobutton-checkbox/[^]
you can try using javascript..check this links..may be u will get help...