I have created a label called txt1
programmatically inside a private void when the app is running ( in runtime ), I want to change the text of this label inside another private void, but I can't get access to txt1
from another void!
script for creating the label dynamically:
private void labelCreate()
{
Label txt1 = new Label();
}
script for changing the text of txt1
which has been created in labelCreate
void ( & this script doesn't work because txt1
has not been declared as a control ):
private void labelTextChange()
{
txt1.Text = "Hello World!";
}
Update 1: I need to create 100 labels which have different names then I will use a for
statement for creating 100 labels. I can't declare 100 global variables. So I need to pass the variables instead of declaring them as global.
Update 2: Is it possible to declare 100 labels inside a for
statement as global?
Update 3: Suppose that I want to fetch some data from a DB, I want to show them separately in unique labels. So I name each label & I change the texts of them according to different data that I get from DB! So I need 2 voids: one for creating the labels according to the number of rows that I get from DB & the other void for changing the texts of labels which I have created before!
Question: How can I have access on a control which has been created in different void? If there is an answer please share the link :)
Thanks