By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

Problem with anchor tag in '.aspx' page

100+
P: 126
Hello everyone,

I am new beginner to asp.net and c#.

I have the following anchor tag in my "Index.aspx" page:
<a href="www.google.com" target="_blank">Google</a>

And, when I click on the above link it is going to:

"http://localhost:1100/CSMS/www.google.com"

instead of:
"www.google.com"

Please help me out.

Thanks a million in advance.
Nov 26 '08 #1
Share this Question
Share on Google+
14 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
Change your link to:
Expand|Select|Wrap|Line Numbers
  1. <a href="http://www.google.com" target="_blank">Google</a>
and see if that works.
Nov 26 '08 #2

Plater
Expert 5K+
P: 7,872
This is not a .NET issue, this is an "HTML 101" issue.
You need to have the http:// in your links.
I also recommend a basic tutorial in html design.

I will move this thread.
MODERATOR
Nov 26 '08 #3

100+
P: 126
@Plater
Hello Guys,

The link is not going to Google home page even if I include 'http://' in the href tag.

<a href="www.google.com" target="_blank">Google</a>

The above mentioned link is working perfectly fine if I use in html page (say index.html)

But, if I use the same above link in a .NET page (say index.aspx), the page is automatically adding the fully qualified URL of ASP.NET server to the URL in href attribute.

Please note that the above mentioned error is occurring only in .NET pages.
Nov 26 '08 #4

Curtis Rutland
Expert 2.5K+
P: 3,256
Navigate to the page, and then View Source. Tell us if the source still shows the same thing, or if it has changed itself to include the fully qualified link.
Nov 26 '08 #5

100+
P: 126
@insertAlias
Thanks for the reply.

The 'index.aspx' page source code still contains the following link

<a href="www.google.com" target="_blank">Google</a>

Please help me out. I am breaking my head to solve this issue from past 5 hours.

Thanks.
Nov 26 '08 #6

Curtis Rutland
Expert 2.5K+
P: 3,256
Well, then it's really not an ASP.NET issue, because that all happens on the server. It is strange though...

Let me think about that....
Nov 26 '08 #7

drhowarddrfine
Expert 5K+
P: 7,435
"target" is an attribute used in frames and that's why it's acting strange. I'll get back to this in a sec.
Nov 26 '08 #8

drhowarddrfine
Expert 5K+
P: 7,435
I haven't dealt with this in years but you would set the href for where you wanted the frame to get its content from and target would be the name of the frame to get the content. So what you have now won't work that way.

Sorry, gotta go.
Nov 26 '08 #9

100+
P: 126
@insertAlias
Hello InsertAlias,

Sorry for not closing the webpage and running it again through the ".Net" server after adding 'http://' to the href attribute in <a> tag. I only refreshed it previously.

Anyways, now I am able to open Google page using the following link:

<a href="http://www.google.com" target="_blank">Google</a>

But this is what I am doing, I am asking the user to enter URL in a textbox and when they click submit button the URL will be stored in the database.

And from the database I am retrieving the URL and creating <a> tags as follows:

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ID="CMLinkRepeater" runat="server"><ItemTemplate> 
  2.     <a href="<%#DataBinder.Eval(Container.DataItem,"CMLink_URL") %>" target="_blank"><%#DataBinder.Eval(Container.DataItem,"CMLink_Name") %></a>
  3.     <br /> 
  4. </ItemTemplate></asp:Repeater>
  5.  
But, with the above procedure the user is able to open the link only if they enter, say "http://www.google.com" in the textbox.

What if they enter "www.google.com" in the textbox? How can I overcome this issue?
Nov 26 '08 #10

100+
P: 126
Thanks for all your help.

Solved the problem.

I just checked whether the URL entered by a user in the textbox has "http://" string or not.

if it is not, I added "http://" to the URL and stored it in the database.

Thank you very much InsertAlias for your help. Happy Thanksgiving Holidays!
Nov 26 '08 #11

Curtis Rutland
Expert 2.5K+
P: 3,256
Well, I found this regex some time ago, that will validate URLs:
Expand|Select|Wrap|Line Numbers
  1. (http|ftp|https)://([\w-]+\.)+(/[\w- ./?%&amp;=]*)?
You could run the URL through that, if it fails, prepend "http://" to it and then check it. If it passes, keep it with the http://, otherwise, let the user know that they have entered an invalid URL.
Nov 27 '08 #12

drhowarddrfine
Expert 5K+
P: 7,435
In any case, all this is totally invalid HTML so keep that in mind.
Nov 27 '08 #13

Curtis Rutland
Expert 2.5K+
P: 3,256
But it's rendered into proper HTML by the server, before it gets to the browser.
Nov 27 '08 #14

Plater
Expert 5K+
P: 7,872
I think he was talking about: target="_blank"
I don't think that is still a valid part of the specs
Dec 1 '08 #15

Post your reply

Sign in to post your reply or Sign up for a free account.