Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi need some assistance..
My form contains 1 button and 1 picbox.
i created dynamic labels controls on page load event by calling a function where i declare labels creating code.
I want when i click on the button i want to remove all labels.
when i run this code on the function i created label show no error "this.Controls.Remove(labels);"
But when i run this code on button click event it show this error "The name 'labels' does not exist in the current context" can any one please show me way to fix it ASAP.
Posted
Comments
BillWoodruff 13-Apr-15 7:15am    
If 'labels is a collection "this.Controls.Remove(labels)" does not make sense. There are other reasons the name 'labels may not exist in the scope of where you call it.

Show the code where you define 'labels. Remember we can't see your code/screen.
lukeer 13-Apr-15 9:07am    
Is this Windows Forms, WPF, ASP.NET, ...? Please tag your question accordingly. Use the Improve Question link for that.

It might be because of the "this" keyword, inside the button click event handler "this" refers to the button object, where as when you added the lables in page load event "this" refers the page object.

this might help you :
https://msdn.microsoft.com/en-us/library/aa984275(v=vs.71).aspx[^]
 
Share this answer
 
Can you provide the code for more clarification.
 
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