3

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?

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.