Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 994
Peter Avatar asked Aug 09 '10 15:08

Peter


2 Answers

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.

like image 94
SLaks Avatar answered Sep 17 '22 13:09

SLaks


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.

like image 28
kbrimington Avatar answered Sep 18 '22 13:09

kbrimington



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!