Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How should I access a label inside a panel in c# inside an if condition?
Posted
Updated 25-Jul-11 21:34pm
v2

Or, if you know the name of the label and merely want to change it,

Label1.Text = "New Text";



Here[^] is a useful guide.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Jul-11 14:52pm    
Correct, my 5. In other words, it does not matter which controls are parent of which.
--SA
C#
Label myLabel = myPanel.FindControl("myLabel") as Label;
if (myLabel != null) {
   //Do your stuff here
}
 
Share this answer
 
if(Label1.Text=="0")
{
//Some statements
}

Label1 is the name of that label
 
Share this answer
 
Comments
[no name] 26-Jul-11 4:28am    
Why Label1.Text == "0" ? Does the property return "0" when the label is empty?
lukeer 26-Jul-11 6:17am    
No, it doesn't. The given code executes "Some statements" in case Label1 indeed shows a "0".

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