User Control

G

Guest

I have a label in a user control and I want to be able to modify the text
from the code behind the page using the user control. How can I do this? I've
tried buy using the following code but I receive a message saying the
property is "inaccessable due to it's protection level

a.b.text = "xxx"

"a" = user control id
"b" = label control id

Thanks for the help
 
I

InK_

Hi!

You have as least 2 solutions:
1) to define your label variable as public
public Label b;
Thus you will be able to access it through your usercontrol form:
a.b.text = "xxx"

2) You can make a property in UserControl which will control changing text
of the label.
e.g.

private Label b;

public string LabelText
{
get
{
return b.Text;
}
set
{
b.Text = value;
}
}

Then you will be able to access to it as follows:
a.LabelText = "xxx"

I prefer the second solution. It gives less control on the label to the end
user of your UserControl. But of cause it depends of the purpose.

Regards,
Inna Stetsyak aka InK_
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top