473,409 Members | 2,006 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,409 software developers and data experts.

validated if textbox is empty and not empty ,and what is the proper if else statement

Validated if textbox is empty and not empty ,and what is the proper if else statement:
Expand|Select|Wrap|Line Numbers
  1. private void btnSave_Click(object sender, EventArgs e)
  2. {
  3.   if (txtFName.Text == "")
  4.   {
  5.     labelID.Text = "!";
  6.   }
  7.   if (txtLName.Text == "")
  8.   {
  9.     labelLN.Text = "!";
  10.   }
  11.   if (txtMI.Text == "")
  12.   {
  13.     labelMN.Text = "!";
  14.   }
  15.   if (cmbGender.Text == "")
  16.   {
  17.     labelGender.Text = "!";
  18.   }
  19.   if (cmbCollege.Text == "")
  20.   {
  21.     labelCollege.Text = "!";
  22.   }
  23.   if (txtFName.Text == "" || txtLName.Text == "" || txtMI.Text=="" || cmbGender.Text=="" || cmbCollege.Text=="")
  24.   {
  25.  
  26.     MessageBox.Show("Fill up the remaining field/s");
  27.   }
Nov 23 '14 #1
1 1158
Frinavale
9,735 Expert Mod 8TB
What's wrong?
Your code looks fine to me...?

You could use the String.IsNullOrEmpty Method or the String.IsNullOrWhiteSpace Method to check if strings contain information...
Nov 24 '14 #2

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

Similar topics

8
by: CMAR | last post by:
I create my website using Front Page 2000. I notice that none of my pages have a DocType statement at the top. I have read that if you want IE6 to use "Standards mode" rather than the "Quirks...
18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
5
by: Yuelin | last post by:
Hi there What's the best way of checking whether a textbox is empty? Thanks. Yuelin
2
by: paul | last post by:
Hi all, I've been handed some code and, unless I've got the numbering of parentheses wrong, one of the functions has a curious if-else statement. The thing compiles but is it right? I know the...
1
by: ravipatil | last post by:
hi i am adding two numbers in C#.net & i want to check wheather first textbox is empty or not. if empty, then it must display "enter the first number" otherwise value is stored in first textbox1....
2
by: juan-manuel.behrendt | last post by:
Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable "lGwU" through an if elif, else...
2
by: pradeep.thekkottil | last post by:
I'm setting up an auction website using PHP and MySQL. There in the section where logged in members can put up new auction in a form, I want to run a form validation where I used if else statements...
4
by: sbandalli | last post by:
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...
4
by: tastingoo | last post by:
Hi, I'm having problems accessing the worksheet after creating the worksheet in an IF statement. For some reason, if I create the worksheet in the else statement, my $rxsheet address is gone...
2
by: Synthologic | last post by:
Hello, I am trying to disable the save or add new button if a textbox is empty on an access form but it is not working, the button is still enabled. So I disable in the button property's panel and...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.