Inline Code in markup page in ASP.NET Webforms?

5.7k Views Asked by At

Is something similiar to the following pseduocode possible on server side controls?

<asp:Label runat="server" ID="lbl" Text=<%=DateTime.Now.ToString(); %> />

I.e. assigning attributes.

2

There are 2 best solutions below

0
On

Try this:

<asp:Label runat="server" ID="lbl" Text='<%=DateTime.Now.ToString()%>' /> 
0
On

This will work for databound controls, e.g.

<asp:Label runat="server" ID="lbl" Text="<%# DateTime.Now.ToString() %>" />

Then in your code behind, you'll need to call lbl.DataBind().