0

I'm clearly missing something fundamental here but could someone explain why label 2 isn't populated?

My codebehind

public partial class namespace : System.Web.UI.Page
{
    public string TestString = "test";

    protected void Page_Load(object sender, EventArgs e)
    {
        lbl1.Text = TestString;
    }

}

my aspx text labels:

<asp:Label ID="lbl1" runat="server" /><br/>
<asp:Label ID="lbl2" runat="server" Text='<%# TestString %>' /><br />
Gordon Copestake
  • 1,616
  • 4
  • 21
  • 37

1 Answers1

3

<%# %> is used for binding in data controls like this : <%# Eval("id") %>, you are trying to write a property on code front.

try this:

<asp:Label ID="lbl2" runat="server"><%= TestString %></asp:Label>
Amir Sherafatian
  • 2,083
  • 2
  • 20
  • 32