如何在aspx页面标记上绑定服务器端功能?

时间:2014-07-01 15:01:27

标签: c# asp.net .net-4.5

是否有类似的东西?

<a id="username" href="http://www.prepp.me/profile/<%: GetUserGUID()  %>"><%: Context.User.Identity.Name %></a>

使用此类服务​​器端代码:

public string GetUserGUID()
        {
            PREPP2Entities db = new PREPP2Entities();
            var uid = (from a in db.Users where a.Login.Contains(Context.User.Identity.Name) select a.UserGUID).First();
            return uid;
        }

1 个答案:

答案 0 :(得分:0)

请试试这个

C#功能:

 public string GetText()
    {
     //your functionality
    }

Aspx页码:

 <asp:Label ID="Label1" runat="server" Text='<%=GetText()%>'></asp:Label>