asp.net必填字段校验器至少有一个文本框,包含文本 [英] asp.net required field validator for at least one textbox contains text
本文介绍了asp.net必填字段校验器至少有一个文本框,包含文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个asp.net Web窗体,我怎么/可以使用必填字段校验,以确保它们中的至少一个包含文本的三个文本框?
I have three textboxes on an asp.net webform, how/can I use a required field validator to ensure that at least one of them contains text?
推荐答案
我会用一个CustomFieldValidator是这样的:
I would use a CustomFieldValidator like this:
<asp:CustomValidator runat="server"
ID="MyCustomValidator"
ValidationGroup="YOUR_VALIDATION_GROUP_NAME"
OnServerValidate="MyCustomValidator_ServerValidate"
ErrorMessage="At least one textbox needs to be filled in." />
,然后在codebehind您有:
and then in your codebehind you have:
protected void MyCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
if (/* one of three textboxes has text*/)
args.IsValid = true;
else
args.IsValid = false;
}
您还可以添加一个客户端组件,此验证,并使其性感与AJAX工具包的ValidatorCalloutExtender控制扩展它。
You can also add a Client-side component to this validation, and make it sexy by extending it with AJAX toolkit's ValidatorCalloutExtender control.
这篇关于asp.net必填字段校验器至少有一个文本框,包含文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文