471,886 Members | 1,018 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,886 software developers and data experts.

Problem with anchor tag in '.aspx' page

126 100+
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:


instead of:

Please help me out.

Thanks a million in advance.
Nov 26 '08 #1
14 28963
Curtis Rutland
3,256 Expert 2GB
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
7,872 Expert 4TB
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.
Nov 26 '08 #3
126 100+
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
3,256 Expert 2GB
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
126 100+
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.

Nov 26 '08 #6
Curtis Rutland
3,256 Expert 2GB
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
7,435 Expert 4TB
"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
7,435 Expert 4TB
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
126 100+
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>
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
126 100+
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
3,256 Expert 2GB
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
7,435 Expert 4TB
In any case, all this is totally invalid HTML so keep that in mind.
Nov 27 '08 #13
Curtis Rutland
3,256 Expert 2GB
But it's rendered into proper HTML by the server, before it gets to the browser.
Nov 27 '08 #14
7,872 Expert 4TB
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.

Similar topics

7 posts views Thread by neverstill | last post: by
1 post views Thread by Roshawn | last post: by
2 posts views Thread by Ken Slight | last post: by
3 posts views Thread by remy.bur | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.