Groups | Blog | Home
all groups > dotnet general > november 2005 >

dotnet general : User Control



Gary
11/30/2005 11:16:02 PM
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
--
Gary Monk
American Dream Home Loans
InK_
12/1/2005 12:00:00 AM
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_

[quoted text, click to view]


AddThis Social Bookmark Button