I have a question regarding the page markup of a hyperlink. I have a form view on an aspx page which has a datatable bound to it in the code behind. I have some controls on the aspx page that get data bound to them in the markup. I have a hyperlink control that needs one field bound to it in the text property (which I figured out) and one field bound to it in the hyperlink propoerty (which I need help with). I got the page to somewhat accept the markup, but when the link it clicked the link is somehow broken.
Also, can I not use the navigate URL property to navigate to an outside URL? Say, WWW.ESPN.COM? I think that is the problem...
<asp:HyperLink runat="server" ID="lnkCustom" NavigateUrl='<%#DataBinder.Eval(Container.DataItem, "WebCustomHyper")%>' Target="_blank" CssClass="weblinks">
<%# DataBinder.Eval(Container.DataItem, "WebCustomHyperDesc")%></asp:HyperLink>
Any Ideas?
Also, can I not use the navigate URL property to navigate to an outside URL? Say, WWW.ESPN.COM? I think that is the problem...
Indeed that may very well be the problem. It depends on what the rendered client-side markup looks like. Let's say, for the sake of argument, that the page is at http://www.example.com/page.aspx
. Then if the link looks like this:
<a href="www.espn.com">click here</a>
Clicking it will try to take the user to:
http://www.example.com/www.espn.com
Which, of course, won't work. This is because the value www.espn.com
alone doesn't tell the browser that it should be going to a different location. It's entirely possible that you have a file on the server called www.espn.com
as far as the browser is concerned.
In order to direct it properly, you need to fully-qualify the URL. Which basically means you need to prepend the protocol prefix. Something more like this:
<a href="http://www.espn.com">click here</a>
This would fix the link and direct the user to the correct destination.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.