How to initialize an ASP.NET user control with a parameter?

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

How do I pass a string value to an ascx page so that it can appear on the ascx page label at the beginning?

+3
source share
2 answers

Add this ...

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

to the ascx control. Then from the page you insert, you can simply set the text as ...usercontrol.Whatever = "text to display";

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

+6
source

, , , .

, , , Initialize, , .

+1

Source: https://habr.com/ru/post/1713300/


All Articles