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

Peter picture Peter · Aug 9, 2010 · Viewed 15.6k times · Source

I am trying to do this:

<asp:HyperLink NavigateUrl='<%= WebContext.RootUrl %><%= WebContext.CurrentUser.UserName %>' runat="server" Text='<%= GetProfileImage(WebContext.CurrentUser.AccountId) %>'></asp:HyperLink> 

But am getting the error:

this is not scriptlet. will output as plain text.

when I mouse over my declarative statements.

Any ideas? Thanks.

Answer

SLaks picture SLaks · Aug 9, 2010

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.