473,387 Members | 1,876 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,387 software developers and data experts.

check whether a textbox is empty

Hi there

What's the best way of checking whether a textbox is empty? Thanks.

Yuelin
Nov 15 '05 #1
5 50095
If you want to ignore spaces, then

textBox1.Text.Trim() == ""

otherwise use

textBox1.Text == ""

Chris
"Yuelin" <li***@lineone.net> wrote in message
news:#O*************@TK2MSFTNGP12.phx.gbl...
Hi there

What's the best way of checking whether a textbox is empty? Thanks.

Yuelin

Nov 15 '05 #2
In article <#O*************@TK2MSFTNGP12.phx.gbl>, li***@lineone.net says...
Hi there

What's the best way of checking whether a textbox is empty? Thanks.

Yuelin


Subclass TextBox and add a IsEmpty Method

class MyTextBox : TextBox
{

public bool IsEmpty()
{
return (TextBox.Text == "")
}

}
--
Thanks
Mark Marsella
Nov 15 '05 #3
Seems a bit excessive...
"Mark Marsella" <ne**@tersus-solutions.com> wrote in message
news:MP************************@news.cis.dfn.de...
Subclass TextBox and add a IsEmpty Method

Nov 15 '05 #4
The more .Net oriented way is to use

TextBox.Text == String.Empty

It doesn't really matter but it goes back to that magic number thing.
There should never be an instance theoretically that you should ever
have to put a string or number in your program.

Nick

Mark Marsella wrote:
In article <#O*************@TK2MSFTNGP12.phx.gbl>, li***@lineone.net says...
Hi there

What's the best way of checking whether a textbox is empty? Thanks.

Yuelin

Subclass TextBox and add a IsEmpty Method

class MyTextBox : TextBox
{

public bool IsEmpty()
{
return (TextBox.Text == "")
}

}


Nov 15 '05 #5
I always do

textBox1.Text.Length == 0

I read somewhere that checking the string's length is a faster operation.
Although the performance gain would probably only be useful in a loop, and
there's little chance you're doing this in a loop...

~Greg

"Chris Capel" <ch***@nowhere.com> wrote in message
news:#c**************@TK2MSFTNGP10.phx.gbl...
If you want to ignore spaces, then

textBox1.Text.Trim() == ""

otherwise use

textBox1.Text == ""

Chris
"Yuelin" <li***@lineone.net> wrote in message
news:#O*************@TK2MSFTNGP12.phx.gbl...
Hi there

What's the best way of checking whether a textbox is empty? Thanks.

Yuelin


Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: vishal | last post by:
hi i am building aan application which will send mail to user when he registers on my site and i am checking whther the email id is working properly or not by sending his email and then cheking...
2
by: mshngo | last post by:
Hi, What would be the best way to check whether an istringstream object has empty buffer? I wanted to do something like: istringstream isStr(myStringContent.c_str()); while...
1
by: Siu | last post by:
Hi, in my ASP.NET (C#) application I would like to check in advance if a node exist: my code is as follow: XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(XML_FILENAME); XmlNode...
1
by: kiran | last post by:
How to check whether the given application is running or not in the current machine. From, my cshartp program I want check whether the yahoo messenger process is running ro not..? if the process is...
4
by: Jiho Han | last post by:
What is the best way to check whether the page is simply a postback or the form has been submit with the intention of doing something? In the olden days, I used to check for a form field name...
5
by: zimmy | last post by:
Hi, Is it possible to check whether ASP.NET is installed on a machine, within a program that I'm writing in C#? And if it's installed, can I check if it is enabled? How? Thanks
11
by: ItsMe | last post by:
Hi, I've 50 MDI Forms in my project, so trying to create MDI Child Form from this procedure. But the problem is, unable to declare as "NewFormName". It gives me an error. Is there any other...
0
by: EgoSum | last post by:
Hi, Is there any way to check whether the print queue is empty?
23
by: mathewgk80 | last post by:
Hi all, I would like to get the Javascript code to check the textbox contains only numeric values or numbers.. I am using asp.net and c#.net.. Please help me.. Regards, Mathew
12
by: foolsmart2005 | last post by:
There are 10 webpages on the host, e.g. 001.html, 002.html, 003,html, 004.html, ......010.html I want to check whether the page is the last page. How can I do. In the index.html -Go to last...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.