RequiredFieldvalidator [英] RequiredFieldvalidator
本文介绍了RequiredFieldvalidator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网页中有四个文本框.我想应用必填字段验证器,以便至少需要一个文本框值,这是强制性的,必须具有四个值中的任何一个.
Hi,
I have four textboxes in my web page. I want to apply required field validator such that atleast one of the text box value is required,it is mandatory to have value in any one of the four . how to validate that.
推荐答案
我建议您编写JavaScript代码来实现这一目标:
非常简单.做这样的事情
I would suggest you to write javascript code to achieve this:
Its pretty simple. Do something like this
function validateTextboxes()
{
if((document.getElementById(''txtbox1'').value == "") && (document.getElementById(''txtbox2'').value == "") && (document.getElementById(''txtbox3'').value == "") && (document.getElementById(''txtbox4'').value == ""))
{
alert(''alert msg'');
return false;
}
else
{
return true;
}
}
调用按钮的onClientclick函数.如下所示:
Call the function onClientclick of button.. something like this:
OnClientClick="return validateData();"
在服务器端,请在执行操作之前进行相同的检查,以便如果禁用了javascript,则仍会执行验证.
希望对您有帮助!
On server side do the same checking before doing operations so that if javascript is diabled, validation is still performed.
Hope this helps!!!
您也可以使用AJAX进行服务器端验证,而无需执行完整的回发.在此处查看更多信息:使用Ajax进行ASP.NET验证.
另外,AJAX Control Toolkit的一些扩展可以执行相同的操作:
You could also do server side validation without performing a full postback with the use of AJAX. See more here: ASP.NET Validation using Ajax.
Also, there are some extensions to the AJAX Control Toolkit that can do the same thing: AJAX Server-Side Validation.
这篇关于RequiredFieldvalidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文