473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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:

"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
14 29287
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
Plater
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.
MODERATOR
Nov 26 '08 #3
JFKJr
126 100+
@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
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
JFKJr
126 100+
@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
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
drhowarddrfine
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
drhowarddrfine
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
JFKJr
126 100+
@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
JFKJr
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
drhowarddrfine
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
Plater
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

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

Similar topics

7
by: neverstill | last post by:
hi- I have <a> tags in my DataList. For the href property, I want to do something like this: <a href='~/Default.aspx?show=Support&disp=Faq&p=<%# DataBinder.Eval(Container.DataItem, "name")%>'...
1
by: Roshawn | last post by:
Hi All, I have created a web user control. This control mimics the numeric pagers seen on many online bookstores. I made this user control using the Repeater. It is populated dynamically. ...
3
by: DonnyW | last post by:
I am working on an application that displays a list of items (biglist.aspx). With each item, there is a link that takes the user to another aspx page for updating the specific details of that item...
3
by: gary | last post by:
Hi, I am trying to reference an anchor in a user control with a url. This worked in 1.1 but no longer works in 2.0. The ascx control is located in a "/include" folder If you have a...
2
by: Ken Slight | last post by:
Hello. Does anyone know how to navigate to a specific anchor within an ASPX page? For example, I have <a name='Test'>Hey there</a>, and I want to direct someone to that anchor in the PageLoad...
3
by: remy.bur | last post by:
Hi, When adding an anchor (which is runat="server") in a user control, the link generated will be based on the user control location and not on the page which is using the control location. For...
1
Steve Kiss
by: Steve Kiss | last post by:
Hi. I am developping a site for which one of the pages uses querry strings to pass some parameters. I can use the querry strings if I call the page from a plain html anchor. However, when I add the...
1
by: shapper | last post by:
Hello, I am applying a style to a anchor tag. This anchor is created by an ASP.NET page and is inside a list item. I know the style is working because I applied it to the anchor in a page that...
4
by: shahidrasul | last post by:
hi in my project when i click on logout anchor it goes to logout page and my code in logout page is if (Session != null) { Session = null; Session.Abandon(); ...
2
by: pavanip | last post by:
Hi, I have one web page in that i am using one anchor tag and linking to some other page in Anchor href. Now i want to raise anchor click event automatically in page load without clicking and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.