Solved

C#, ASP.NET 2.0, Textbox validation question

Posted on 2007-03-21
2
565 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now