AshOoO AshOoO - 1 year ago 143
ASP.NET (C#) Question

I want to get property value from code behind

I have a case that I need to set the Text property for an asp label in the aspx page not from code behind. More exactly, I need to set a value to asp control in aspx page and this value is set by a property in the same page code behind.

so I need to use an expression to do that like:

<asp:Label Text="<%= MyProperty %>" ..../>

I use:

<%= MyProperty %> doesn't work.
<%# MyProperty %> doesn't also.

Answer Source


public partial class _Default : System.Web.UI.Page
    public string CustomTitle = "This Is Title";

    protected void Page_Load(object sender, EventArgs e)


<asp:Label Text='<%#CustomTitle %>' runat="server" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download