Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Validating only one of two controls

Reply
Thread Tools

Validating only one of two controls

 
 
Darrel
Guest
Posts: n/a
 
      11-15-2004
(whew...I'm full of questions tonight!)

I have two textBoxes that I need to validate. One's a phone number and one's
an email address. I need to only validate one of them, though. (ie, only
email or only phone are required).

How can I do this? I've set up a custom control the checks both of these
fields and if they're both blank, it returns a 'one of the two must be
filled in' error.

I think I'd like to do something like this:

if textbox.text > "" then validate with regex validator

but I'm not sure how to go about that.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGF0cmljay5PLklnZQ==?=
Guest
Posts: n/a
 
      11-15-2004
Darrel..place CausesValidation="False" to the button !
like:-
<asp:Button runat="server" id="YourIDButton" text="YourText"
CausesValidation="False"></asp:Button>
Hope i understand what u want!


"Darrel" wrote:

> (whew...I'm full of questions tonight!)
>
> I have two textBoxes that I need to validate. One's a phone number and one's
> an email address. I need to only validate one of them, though. (ie, only
> email or only phone are required).
>
> How can I do this? I've set up a custom control the checks both of these
> fields and if they're both blank, it returns a 'one of the two must be
> filled in' error.
>
> I think I'd like to do something like this:
>
> if textbox.text > "" then validate with regex validator
>
> but I'm not sure how to go about that.
>
>
>

 
Reply With Quote
 
 
 
 
Peter Blum
Guest
Posts: n/a
 
      11-15-2004
I see this problem all of the time.

The ASP.NET validators do not handle this behavior automatically. Instead,
you have to use the CustomValidator and write the logic in your own
evaluation function. The trickiest part is writing the client-side function,
when you don't know DHTML and JavaScript. Many users have not done this part
and live with a server side only validator.

I built a replacement to Microsoft's validators that handles this.
"Professional Validation And More" (http://www.peterblum.com/vam/home.aspx)
includes 22 validators. Its MultiConditionValidator is designed for this. It
lets you merge the logic of other validators together into a boolean
expression like "TextBox1 is Required OR TextBox2 is Required". It generates
the javascript for you. All javascript runs on IE, IE/Mac,
Netscape/Mozilla/FireFox, Opera 7 and Safari whereas Microsoft's only
handles the IE browsers.

--- Peter Blum
www.PeterBlum.com
Email:
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Darrel" <> wrote in message
news:...
> (whew...I'm full of questions tonight!)
>
> I have two textBoxes that I need to validate. One's a phone number and
> one's an email address. I need to only validate one of them, though. (ie,
> only email or only phone are required).
>
> How can I do this? I've set up a custom control the checks both of these
> fields and if they're both blank, it returns a 'one of the two must be
> filled in' error.
>
> I think I'd like to do something like this:
>
> if textbox.text > "" then validate with regex validator
>
> but I'm not sure how to go about that.
>
>



 
Reply With Quote
 
Darrel
Guest
Posts: n/a
 
      11-15-2004
> I built a replacement to Microsoft's validators that handles this.
> "Professional Validation And More"
> (http://www.peterblum.com/vam/home.aspx) includes 22 validators. Its
> MultiConditionValidator is designed for this. It lets you merge the logic
> of other validators together into a boolean expression like "TextBox1 is
> Required OR TextBox2 is Required". It generates the javascript for you.
> All javascript runs on IE, IE/Mac, Netscape/Mozilla/FireFox, Opera 7 and
> Safari whereas Microsoft's only handles the IE browsers.


Peter:

A belated thanks for your answer! I'll definitely take a look at that.

The custom validator makes sense. Actually, in this case, I was able to get
away with having the custom validator check to make sure they aren't both
empty. Then, I validated both with a regex. The regex checks for either a
valid entry OR a blank field. So, in the end, that worked. At least for
these two particular fields.

-Darrel


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating User Input (numeric only, and valid email address attributes) charleswesley@gmail.com ASP .Net 2 10-01-2005 07:49 PM
validating only a part of the form Joe Abou Jaoude ASP .Net 4 03-18-2005 05:49 PM
CSS aligning two things on one line with one left and one right news.frontiernet.net HTML 6 04-16-2004 02:44 AM
Validating against XSD given only a DOM Node Nazghal Java 0 12-09-2003 04:16 AM
Custom controls instance problem on PostBack - two controls, one instance ??? Dejan Vesic ASP .Net Web Controls 0 08-20-2003 02:43 PM



Advertisments