Control Validation

  • Thread starter Thread starter KJ
  • Start date Start date
K

KJ

I need help.

I have a checkbox and two textboxes on a webform. How can I validation
if a person either enters something in the two textboxes OR the
checkbox?

I tried using a custom validator but that is not working like I want
it.

Please help. I know this sounds easy but I cannot figure it out.
Thanks
 
Custom Validator is the way to go. Something like this on the client side:

<SCRIPT LANGUAGE="JavaScript">
<!--
function validateControls(sender, args)
{
if(document.Form1.chkBox.value || document.Form1.txtBox.value != "")
{
args.IsValid = true
}
else
{
args.IsValid = false
}
}
//-->
</SCRIPT>

You would then need to write server side code in the validator's
ServerValidate event handler that is written in whatever .NET language you
are working that would do the same thing as this client side code.
 
Hi KJ,

Scott's solution is correct. However, it has a couple of shortcomings. You
still have to figure out the client-side (javascript) code if you want
client-side validation and all client-side validation is still limited to IE
browsers as Microsoft's validators only support DHTML on the client-side.

Scott wrote an article on the subject of supporting validation on other
browsers: http://aspnet.4guysfromrolla.com/articles/051204-1.aspx
He graciously notes that my software, "Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx) solves this problem.
It also solves the problem of building the javascript. I provide 22
validators including one that can handle a checkbox and another that can
combine any of the validators into a boolean expression. You can describe
your logic: checkbox checked or (textbox1 has text and textbox2 has text).
It creates the client-side and server side functions for you.

I wrote "Professional Validation And More" because there are so many
limitations in Microsoft's validators that keep forcing you to write custom
code and hacks. For a list of those limitations, see
http://www.peterblum.com/vam/valmain.aspx. It will help you as you plan your
site's validation design, even if you don't use my solution.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
Scott's solution is correct. However, it has a couple of shortcomings. You
still have to figure out the client-side (javascript) code if you want
client-side validation and all client-side validation is still limited to
IE browsers as Microsoft's validators only support DHTML on the
client-side.

Huh, I provided the client-side (JavaScript) code in my first reply. And,
since it is a CustomValidator that we are talking about (which requires that
you write the client code yourself) the client code should be written using
either the W3C DOM or standard BOM (which I have done), so my provided code
will work in most browsers.
 
No, I don't think so. Peter Blum posted a reply after mine (which was the
first reply to the OP stating that my solution was correct but had
shortcomings (he must have been referring to me because mine was the only
other reply to the post. He then goes on to talk about your work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top