开发者

Required fields one of two fields

I am writing in asp.net c#.

I want a control similiar to RequiredFieldValidator except I want one of two fields to be required. I found an excellent开发者_开发百科 example for two text fields but in my case one field is a check box and the other is an text box. If the check box is not checked the text box must be entered.

Any thoughts?


Just use javascript or C# code to check this. I personally don't care for the RequiredFieldValidator types as they are limited and rather confusing.

With C# server side code you could just check

if (!chk.Checked && txtBox.Text.Length==0)

For JavaScript something to this effect:

if (!(document.getElementById('myCheckBox').Checked) 
     && document.getElementByID('myTextBox').val=='')


You can always use the customvalidator if you have complex custom validation logic. This is probably your best way to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜