[ACCEPTED]-I want to get property value from code behind-asp.net

Accepted answer
Score: 28

Default.aspx.cs

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

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.DataBind();
    }
}

Default.aspx

<asp:Label Text='<%#CustomTitle %>' runat="server" />

0

Score: 14

You have to treat regular HTML and WebControls 4 differently:


regular HTML:

Using <%= ... %> is sufficient:

<span><%= MyProperty %></span>

WebControls (stuff 3 starting with <asp:...>):

<asp:Label Text='<%# MyProperty %>' />

In this case, you 2 also have to call Me.DataBind() (VB) or this.DataBind(); (C#) in your 1 codebehind, since <%# ... %> are data binding expressions.

Score: 4
Page.DataBind();

Do you call this in your code? It binds 1 all variables set in code to your page.

More Related questions