473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Control Validation

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
5 1296
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
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
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nedu N | last post by:
Hi, I want to have confirmation(Yes/No) on a button of the webform in which there are many validation controls. I want all the validation controls to be triggered first and then Yes/No...
2
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
7
by: A.M | last post by:
Hi, I have a validation control in my page that upon any invalid data, it disables all buttons in the page. basicly i don't have any postback in the page if the validator finds any error. How...
2
by: NWx | last post by:
Hi, I have a form with few controls, few validation controls and a validation summary control I set-up appropriate Messages in Validations controls. However, if validation fails, I just want...
2
by: Barbara Alderton | last post by:
I setup some standard Required Field Validation controls and one Custom validation control on an ASP.NET page (within a user control) to validate text entry. I also setup a Summary Control to post...
5
by: Richard Brown | last post by:
Ok, I've been looking through the .NET SDK docs and stuff. I'm wondering if you can provide a control extender that does generic validation or functionality just by dropping it on the form. For...
2
by: c676228 | last post by:
Hi, I have several user controls like email, phone,ssn etc. each has it's own validation message in its user control already. When I bring all those user controls in an aspx page, I would like to...
2
by: ticars | last post by:
I have a telephone number user control in which I need to validate the data entered (Required field validation and regular expression validation). The phone number is represented as 3 text boxes...
1
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.