I am not sure why you are trying to do that, but you can do it by calling the DataBind
method of control like this:-
public string FirstName { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
FirstName = "XYZ";
if (!IsPostBack)
Label1.DataBind();
}
Update:
Data Bind code nuggets <%#
will work only with DataBound Controls. To make them work with normal ASP.NET controls, you will have to explicitly call the DataBind
method of that control like I did above.
Text='<%# "Hello " + this.FirstName %>'
Will print Hello XYZ
here. You can also check this answer for further explanation.