[asp.net] asp control text attribute with in line code <% %>

Costas

Administrator
Staff member
source - http://stackoverflow.com/a/6847569

for instance this :
JavaScript:
<asp:Label ID="lbl" runat="server" Text="<%= Now.ToShortDateString() %>"  />

will print as is the <%= Now.ToShortDateString() %>

the solution is to set the text/value at page_load
JavaScript:
protected void Page_Load(object sender, EventArgs e)
{
	lbl.Text = DateTime.Now.ToShortDateString();
}
 
Top