I have a control on one of my page which takes some user input (URL) and allows the user to test the link.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("URL") %>' Target="_blank">Click here to test link</asp:HyperLink>
The problem is if the user puts in the URL "google.com", then the link will be treated as "http://localhost/google.com". I have to put "http://www.google.com" for it to go to the right place.
Is it possible to treat the link like it is an absolute link in all cases?
Try this...
NavigateUrl='<%# Eval("URL", "http://{0}") %>'
Edit: if you want to add check whether it already contain http://
then it should be like..
NavigateUrl=<%# Eval("URL").ToString().Contains("http://") == true ? Eval("URL") :
"http://" + Eval("URL") %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With