Solved

C#, ASP.NET 2.0, Textbox validation question

Posted on 2007-03-21
2
574 Views
Last Modified: 2013-12-17
I have a web form that has two textboxes on it.  I want to be able to validate that at least one of these boxes is blank before sending the request back to the server.  

If txtbxA.Text = "Something" then txtbxB.Text = ""  or
If txtbxB.Text = "Something" then txtbxA.Text = "" 

I have found ways to validate them to be equal to each other or to be equal to a specific value, but cannot figure out how to validate that one is always blank.

This is probably really easy, and I apologize if it is a stupid question, but I haven't worked much with web forms.  Any help is extremely appreciated.

Thanks
0
Comment
Question by:CantonMarko
2 Comments
 
LVL 13

Accepted Solution

by:
KarinLoos earned 500 total points
ID: 18766581
I normally check the length property of the text to determine if a string is empty.
so ( in c#  something like )
if ( ( textbox1.text.length > 0 & textbox2.text.length == 0) || ( textbox1.text.length == 0 & textbox2.text.length > 0 ) )
{
   // ok to proceed
}
0
 

Author Comment

by:CantonMarko
ID: 18766633
I cannot believe that I was so dumb!!!!  That was just too obvious.  Thank you very much for the suggestion.  It works just fine.  
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
in Dot net,lastest version of MVC 3 33
Regular expression help 2 34
start a process from a service 3 30
Call Controller Action Method from ASPX 2 22
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used. The spreadsheet used in the permutations and combinations  video.:  The spreadsheet used in the permutations and combinations  video. The…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question