problem assigning declarative values in asp:hyperlink. error: this is not scriptlet. will output as plain text

后端 未结 4 1390
星月不相逢
星月不相逢 2021-02-12 15:02

I am trying to do this:

<%= WebContext.CurrentUser.UserName %>\' runat=\"server\" Text=\'&l         


        
相关标签:
4条回答
  • 2021-02-12 15:11
    <a href='<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>'><%= GetProfileImage(WebContext.CurrentUser.AccountId) %></a>
    
    0 讨论(0)
  • 2021-02-12 15:13

    You can still populate an <asp:HyperLink> if you provide the ID and runat="server" properties. You can then set any property of the HyperLink from code-behind.

    ASP Code:

    <asp:HyperLink ID="myLink" runat="server"/>
    

    Code-behind:

    public void Page_Init()
    {
        myLink.NavigateURL = WebContext.RootUrl + WebContext.CurrentUser.UserName;
        myLink.Text = GetProfileImage(WebContext.CurrentUser.AccountId);
    }
    
    0 讨论(0)
  • 2021-02-12 15:14

    You can use data binding syntax <%# %>. Just be sure that your hyperlink is either in a databound control, such as a ListView item template, or that you explicitly call DataBind() on the control from code-behind.

    0 讨论(0)
  • 2021-02-12 15:33

    You cannot use <%= ... %> literals to set properties of server-side controls.

    Instead, you can use a normal (client-side) <a> tag, like this:

    <a href="<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>"><%= GetProfileImage(WebContext.CurrentUser.AccountId) %></a>
    

    If GetProfileImage doesn't return HTML tags, make sure to escape it.

    0 讨论(0)
提交回复
热议问题