hyperlink without http://

When I try to launch a website through a server control hyperlink without the http://   portion it launches incorrectly. For instance if I launch www.cnn.com through

http://www.mysite.com/sites/mysites.aspx  it launches as http://www.mysite.com/sites/www.cnn.com.

1) What I would like to know is why?

2) Is there a way to get it to launch properly without the http:// portion?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if you view the page source after it is rendered to the browser and find the hyperlink you will see that it looks something like this

<a href="www.cnn.com">cnn</a>

if you click on this link from a site www.mysite.com, the link opened will be www.mysite.com/www.cnn.com

1. this isn't an asp.net problem so much as expected behaviour from your web browser.

2. you will need the http:// portion in place to open a site that is external to the site containing the link

I'm guessing you don't have the http:// portion because you are pulling the url back from a database or some such...?  in this case you will need to add it yourself
dotnet22Author Commented:
Is there some javascript function that can be added as an attribute to the hyperlink to avoid this problem.
I would have thought there is, but it would be far more work to do that than to add the http:// in the code

what does the asp:hyperlink look like in your aspx/ascx page?
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

dotnet22Author Commented:
<a id="HyperLink1" href="www.cnn.com" target="_blank">HyperLink</a>
without deliberately being facetious, why can't you do this

<a id="HyperLink1" href="http://www.cnn.com" target="_blank">HyperLink</a>
dotnet22Author Commented:
You could. It's just a matter of checking the value. I just wanted to bypass checking the url and whether it had http or not. So I'm assuming there is no javascript way to do this. Menaing haveing www.cnn.com work correctly without the http:// ?
I'm sure there is a javascript way of doing this, but it would be considerably more work than just checking the url... i've been having a look...

you can add a client side onclick event to the A tag, which accesses the href property - this is the full href, not just what is in the href attribute of the link, so it will be be www.mysite.com/www.cnn.com, so you'd have to do some pattern matching to get at the part you want, then do

location = "http://" + url;  // in javascrpt

if it is the end result of correctly functioning links that you are after, I would recommend not bypassing checking the url in the code.  if you are just after an answer to your original question, then

1. it is supposed to work like that
2. you could using javascript, but it would be a big fat pain in the proverbials

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.