Inline Code in markup page in ASP.NET Webforms?

2019-08-02 19:04发布

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条回答
smile是对你的礼貌
2楼-- · 2019-08-02 19:33

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().

查看更多
ら.Afraid
3楼-- · 2019-08-02 19:51

Try this:

<asp:Label runat="server" ID="lbl" Text='<%=DateTime.Now.ToString()%>' /> 
查看更多
登录 后发表回答