By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,600 Members | 1,683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,600 IT Pros & Developers. It's quick & easy.

Control Validation

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.
"KJ" <kl******@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
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

Nov 18 '05 #2

P: n/a
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: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"KJ" <kl******@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
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

Nov 18 '05 #3

P: n/a
> 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.

Nov 18 '05 #4

P: n/a
FYI, Scott M. <s-***@nospam.nospam> != Scott Mitchell [MVP]
<mi******@4guysfromrolla.com>. I mention this because it seems you
confused me (Scott Mitchell, the author of
http://aspnet.4guysfromrolla.com/art...051204-1.aspx), with Scott M.
--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #5

P: n/a
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.
"Scott Mitchell [MVP]" <mi******@4guysfromrolla.com> wrote in message
news:41**************@4guysfromrolla.com...
FYI, Scott M. <s-***@nospam.nospam> != Scott Mitchell [MVP]
<mi******@4guysfromrolla.com>. I mention this because it seems you
confused me (Scott Mitchell, the author of
http://aspnet.4guysfromrolla.com/art...051204-1.aspx), with Scott M.
--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.