Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a hyperlink in mt aspx page like this:


<asp:Repeater ID="Rpt" runat="server">
    <ItemTemplate>
        <p><%# Eval("Name") %>
        <asp:HyperLink  ID="Url" runat="server" Text ="<%# Eval("Url") %>"/>  </span></p>
    </ItemTemplate>
</asp:Repeater>


as you can i have
<asp:HyperLink  ID="Url" runat="server" Text ="<%# Eval("SiteName") %>"/>  </span>


I'm trying to set the "siteName" as text area where the user will click. for some reason i'm getting an error on that line saying:
Quote:
The server tag is not well formed.


What am i doing wrong or what could i do to make this run?

Many thanks.

What I have tried:

I'm still trying figure out why this is not working
Posted
Updated 20-Jul-17 3:13am
Comments
ZurdoDev 20-Jul-17 9:03am    
asp:Hyperlink's hyperlink property is actually called NavigateUrl. Text is what they will see. And I believe it is single quotes. For a working example, see https://stackoverflow.com/questions/1779481/hyperlink-with-navigateurl-with-eval-where-is-the-mistake

1 solution

<asp:HyperLink  ID="Url" runat="server" Text ="<%# Eval("SiteName") %>"/> 


"Text" and "Eval" are both compiled server-side and when you use quotes for both (") it gets confused as to the bounds of both, so it considers the Text attribute to be everything between the first and second quotes, so;

Text="<%#Eval("


The solution is fairly simple, use apostrophe for outer Text and quote for inner Eval so .net knows the proper boundaries

<asp:HyperLink  ID="Url" runat="server" Text ='<%# Eval("SiteName") %>'/> 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900