By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

How to check if the textbox is empty

P: 53
How to check if the text box is empty in C#?? I have to display an error box if the textbox is empty. I am trying this way,but no results. Thank you for the help.

private void Save_Click(object sender, EventArgs e)
{

if (textBox1.Text == String.Empty)
{

errortextBox2.Visible = true;
errorgroupBox2.Visible = true;
errortextBox3.Visible = true;
errorbutton1.Visible = true;
}
else
{

string itemToAdd = textBox1.Text;
listBox1.Items.Add(itemToAdd);
}
}
Feb 6 '09 #1
Share this Question
Share on Google+
4 Replies


P: 53
I got to know the solution to the problem.Thank you all
Feb 6 '09 #2

Plater
Expert 5K+
P: 7,872
If the textbox is truely empty, that is how to check for it, I suspect your problem might lie elsewhere.
Is this a web application? Are you remember to check for isPostback in your form_load?
Feb 9 '09 #3

P: 53
Hello Plater, Thanks for the reply, I did get it to work. Its a WinForm application...Thanks again...
Feb 9 '09 #4

Dököll
Expert 100+
P: 2,364
While I am glad you got it working, it would be extremly friendly if posted how you did, for someone else looking, or passing by anyway:-)
Expand|Select|Wrap|Line Numbers
  1.             //It's probable adding textbox, checkbox, and other component items to a list will help minimize long if statements, if you have a number of these to do...
  2.             if (this.txtCustomerID.Text == "")
  3.             {
  4.  
  5.                 MessageBox.Show("Please enter values in this Customer ID textbox", "Extreme Cinema TextBox Error");
  6.                 this.txtCustomerID.Focus();
  7.                 return;
  8.             }
  9.  
  10.  
Dec 5 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.