Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicitly treat link as an absolute link?

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?

like image 512
Diskdrive Avatar asked Jun 01 '11 05:06

Diskdrive


1 Answers

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")  %>
like image 158
Muhammad Akhtar Avatar answered Sep 19 '22 00:09

Muhammad Akhtar