hii
friends, i just want to know how to create if-else statement
where we dont allow user to left any textbox blank in our window application , suppose we have 3 textbox then please suggest me how to create if - else statement for this in c#.
thanx in advance.

Pseudocode :
if textbox1 is blank then
do something
else if texbox2 is blank then
do something
else if textbox3 is blank then
do something
else
do something

Typically this question comes up when you don't want the user to leave a dialog form until all of the required text boxes are populated.

If that is the case here, then do not enable the Ok button until the required textboxes are populated. To test when to enable the ok button, write a single event handler for the TextChanged event and assign it to all three textbox controls.

In the event handler;

buttonOK.Enabled = !string.IsNullOrEmtpy(textbox1.Text) 
       && !string.IsNullOrEmpty(textbox2.Text)
       && !string.IsNullOrEmpty(textbox3.Text);

This is much better than a bunch of if..else..else statements.

If this is not a modal dialog type form, and you really need to use if..else statements, then use the format:

if( condition )
{
     ...
}
else if (condition2)
{
   ...
}
else if( condition3)
{
   ...
}

Did you get your answer or still you need some additional info? I think the answer was already been well-said here. I was supposed to add mine but I noticed the complete replies ... so I just want to ask if you are okay now or what.

Personally I like the required field validators for this sort of stuff, but if you wanted an if statement you can also combine them into one

If(textbox1 == "" || textbox2 == "" || textbox3 == "")
     label = "Hey dude you left a textbox blank on us"

or however you want to handle it. You could use multiple if statements as well to set your message specifically as

This article has been dead for over six months. Start a new discussion instead.