[ACCEPTED]-I want to get property value from code behind-asp.net
Accepted answer
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
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.
Page.DataBind();
Do you call this in your code? It binds 1 all variables set in code to your page.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.