views:

611

answers:

2

For example, I have a user control(ascx) with a label inside, I will use the the user control in my aspx page.

How can I pass a string value to the ascx page so that it can be display in the label of ascx page at the beginning?

+4  A: 

Add this...

public string Whatever
{
get { return label.Text; }
set { label.Text = value; }
}

to your ascx control. Then from the page you are putting it in you can just set the text like... usercontrol.Whatever = "text to display";

or you can use the Whatever as a property on the aspx side of the page.

David McEwing
+1  A: 

You can expose whatever controls you want access to in your user control by creating property for them.

In the past when I have had user controls that required certain data for setup I would create an Initialize method which would take in and setup whatever was needed.

Kelsey