Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to C#. I made a program and I am having trouble with Text Box an Label.
Here Is My Code:

C#
if (string.IsNullOrWhiteSpace(TextBox1.Text))
            {
                Label1.Text = null;
            }


But When I execute it Nothing Happens!
I even tried string.empty etc...
Posted
Updated 3-Dec-11 7:17am
v2
Comments
Ed Nutting 3-Dec-11 11:49am    
What are you expecting to happen? The text box will display blank if text is blank or nul.. I'm not even sure you can set the text property to null anyway... Why do you want to? Just use string.IsNullOrEmpty or string.IsNullOrWhiteSpace.
LanFanNinja 3-Dec-11 13:48pm    
Please explain what it is you are wanting to do exactly. I am sure there is a better solution for you than this.

Text boxes are usually not null, so you must check for empty string.
C#
if(TextBox1.Text == "")
    Label1.Text = "" ;
 
Share this answer
 
Comments
Abhinav S 3-Dec-11 13:23pm    
The OP already tried string.empty.
Wonde Tadesse 3-Dec-11 13:29pm    
5+
Mehdi Gholam 3-Dec-11 14:27pm    
Thanks
how bout this?

C#
if(String.IsNullOrEmpty(TextBox1.Text))
{
   Label1.Text = string.Empty
}


Please mark as answer and vote 5 if this solved your problem

Best regards,
Eduard
 
Share this answer
 
C#
private void textBox1_TextChanged(object sender, EventArgs e)
        {
            label1.Text = textBox1.Text;
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900