Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
if (button1.Text == "button1")
           {
               button1.Text = "button2";
           }
           if (button1.Text == "button2")
           {
               button1.Text = "button1";
           }



why its not working
Posted
Updated 19-Apr-13 10:57am
v2
Comments
José Amílcar Casimiro 19-Apr-13 16:44pm    
I see too button2.
Richard C Bishop 19-Apr-13 16:45pm    
What are you trying to accomplish? That code is pointless.

You might want to step through the code line-by-line and think about your logic. You might also want to look at both if statements and see what you're setting the Text of the button to.

BTW: You only need ONE if statement, not 2.
 
Share this answer
 
Comments
apoorv1988 19-Apr-13 16:58pm    
i changed it bt still its not changing the text
Dave Kreskowiak 19-Apr-13 17:03pm    
Look at your logic again. You only need ONE if statement.
[Not an answer, should be removed. Besides, this post makes no sense —SA]

instead of to if conditions i just needed to use if else
 
Share this answer
 
v2
Quote:
if (button1.Text == "button1")
{
button1.Text = "button2";
}
if (button1.Text == "button2")
{
button1.Text = "button2"; // <-- wrong line
}


Wrong line in bold, change it to
button1.Text = "button1";
 
Share this answer
 
Comments
apoorv1988 19-Apr-13 16:51pm    
if (button1.Text == "button1")
{
button1.Text = "button2";
}
if (button1.Text == "button2")
{
button1.Text = "button1";
}

corrected bt still nt working
Dave Kreskowiak 19-Apr-13 17:03pm    
Look at your logic! You're changing the text of the button to "button2", and the checking to see if the text value is "button2" and changing it back! Like I said, you only need if statement, not two.

CPallini 20-Apr-13 4:07am    
'Not working' is not helpful. You should detail the expected behaviour and the observed one.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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