Hyperlink in gridview not working correctly

I have a gridview in my ASP.NET website(VB code) and my last column holds the website of the companies that I am loading into the grid. When I click on the hyperlink Im loading a new tab with the webpage link I just clicked on. The thing is, if the hyperlink has an HTTP the page loads fine but if the hyperlink is a www address it takes the path of the project for some reason and tries to load that with the www and of course that doesnt work.
For instance, the hyperlink I am trying to click on is "www.abc123.com/fa" and when I click on it, or hover over it, I see on the bottom of the page that it has "http://localhost:58626/Trans/www.abc123.com/fa" and everything before the www is the path of my website? But like I said if the hyperlink starts with an http it comes up fine and even shows on the bottom of the page, when I hover over it, the correct site?
My first thought was to check the Gridview RowCommand or RowDataBound event when I click on the hyperlink and fix the path of the site if it starts with www take everything off the front of it and just load the site?
Has this happened to anyone?

Please help me!!

Thanks
JK
jknj72Asked:
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.

jknj72Author Commented:
Just an fyi, this is the markup code for my hyperlink in my gridview. Maybe im doing something wrong here???

<asp:TemplateField HeaderText="Web Site" ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="125">            
     <ItemTemplate>                
     <asp:HyperLink ID="hlWebsite" runat="server" Target = "_blank" Text='<%# Eval("SUPPORTWEBSITE") %>'        NavigateUrl='<%# Eval("SUPPORTWEBSITE") %>'>
    </asp:HyperLink>            
   </ItemTemplate>  
   <HeaderStyle HorizontalAlign="Left" />      
</asp:TemplateField>
0
sammySeltzerCommented:
something like this?

<asp:HyperLinkField ID="hlWebsite" DataNavigateUrlFields="SUPPORTWEBSITE" DataNavigateUrlFormatString="gotopage.aspx?p1={0}" Text="Web Site">

Open in new window

0
sammySeltzerCommented:
Then add your Target = "_blank" there.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

jknj72Author Commented:
"Then add your Target = "_blank" there. "

Where should I be adding this?
0
jknj72Author Commented:
Also this doesnt seem to be working??? It doesnt recognize HyperLinkField so I assumed you meant Hyperlink and then the DataNavigateUrlFields and DataNavigateUrlFormatString are not valid attributes...Can you please explain?

<asp:HyperLinkField ID="hlWebsite" DataNavigateUrlFields="SUPPORTWEBSITE" DataNavigateUrlFormatString="gotopage.aspx?p1={0}" Text="Web
0
jknj72Author Commented:
My last comment  wasnt working because it didnt have an end tag but I got that to work now. So disregard the last comment but I am still at

"Then add your Target = "_blank" there. "
 Where should I be adding this?

Can you help me with this??
0
sammySeltzerCommented:
Anywhere within that line should suffice.

<asp:HyperLinkField ID="hlWebsite" DataNavigateUrlFields="SUPPORTWEBSITE" DataNavigateUrlFormatString="gotopage.aspx?p1={0}" Target = "_blank" Text="Web Site">

Open in new window

0
jknj72Author Commented:
But I need to put the value into the gridview column with the website

 Text='<%# Eval("SUPPORTWEBSITE") %>'

But when I add this it says the HyperLinkField does not have a DataBinding event

After I get this figured out I simply wanna click on the link and bring up the site that is in the text?

I tried changing the text but now Im getting errors??? I think Im close but I need some help still...
0
sammySeltzerCommented:
Ok try this:

                <asp:TemplateField HeaderText="Web Site" SortExpression="SUPPORTWEBSITE">
                 <ItemTemplate>
                   <asp:HyperLink ID="hlWebsite" runat="server" Target="_blank" HeaderText="Web Site" NavigateUrl='<%# Eval("ID","gotopage.aspx?ID={0}") %>' Text = '<%# Eval("SUPPORTWEBSITE") %>' />
                 </ItemTemplate> 
                </asp:TemplateField>

Open in new window

0
jknj72Author Commented:
It bombed on
NavigateUrl='<%# Eval("ID","gotopage.aspx?ID={0}") %>'
It doesnt recognize "ID"??

And when I hover over the links they all have the path to the website before the actual URL

So when I hover over www.abc123.com it tries to open
http://localhost:58626/Trans/gotopage.aspx?ID=www.abc123.com/fa
And I need to open
www.abc123.com/fa

I think we are almost there...What do you think???
0
sammySeltzerCommented:
First, you need a unique identifier for *each* record (hyperlink).

Do you have some sort of primary key on your db?

Replace ID with whatever your primary key is.

Also, replace gotopage.aspx with the page your users will be taken to *after* clicking the link.

Do these things and your stuff will work.

That is *WORKING* example I posted.
0
jknj72Author Commented:
"Also, replace gotopage.aspx with the page your users will be taken to *after* clicking the link."

The page that the user will be taken to is the page of the link they will click on? So should I replace the gotopage.aspx with the column name?

Ex:
<asp:HyperLink ID="hlWebsite" runat="server" Target="_blank" HeaderText="Web Site" NavigateUrl='<%# Eval("VENDORID","SUPPORTWEBSITE") %>' Text = '<%# Eval("SUPPORTWEBSITE") %>' />
0
jknj72Author Commented:
Im doing it wrong. Its trying to pull up the column name and not the site name that the column value.
I put  
<asp:HyperLink ID="hlWebsite" runat="server" Target="_blank" HeaderText="Web Site" NavigateUrl='<%# Eval("VENDORID","SUPPORTWEBSITE") %>' Text = '<%# Eval("SUPPORTWEBSITE") %>' />

When I hover now its pointing to
http://localhost:58626/Trans/SUPPORTWEBSITE(this is a column name and not the column value)
So something is till not right
0
sammySeltzerCommented:
Kind of look at it like this:

Your user is on a landing page called landing.aspx

On this landing page, you want the user to click on a link to go to another page to view something info.

So on landing page, you

<a href="processpage.aspx?id=1234>go to process page</a>

Open in new window


User clicks on go to process page, and will be taken to processpage.aspx.

Infact, if you look at the browser, you will see something like:

Processpage.aspx?1234=something.

Maybe, you can explain what you are trying to achieve when a user clicks on the link.

This is not right:
NavigateUrl='<%# Eval("VENDORID","SUPPORTWEBSITE") %>'

Open in new window

0
jknj72Author Commented:
I hear what you are saying but I am not going to a page within my website I am going to the site in the link

Ok......I have a grid and In the grid I am populating with Vendor information as follows.....

Vendor      Address               City          State       Zip            Web Site

ABC          123 Main Street     Newark     NJ           07652       www.abc123.com

In the column "Web Site" I have a hyperlink with the Vendors website in the column value...(www.abc123.com)

When they click on the value in the Web Site column...I want to go to "www.abc123.com" in a new tab....That is all I want to happen
0
sammySeltzerCommented:
So, on your database, SUPPORTWEBSITE is a columnName and it has a value of www.abc123.com?

If so, then this should work, at least the link should have the value, not the columnane:

                <asp:TemplateField HeaderText="Web Site" SortExpression="SUPPORTWEBSITE">
                 <ItemTemplate>
                   <asp:HyperLink ID="hlWebsite" runat="server" Target="_blank" HeaderText="Web Site" NavigateUrl='<%# Eval("ID","SUPPORTWEBSITE" %>' Text = '<%# Eval("SUPPORTWEBSITE") %>' />
                 </ItemTemplate> 
                </asp:TemplateField>

Open in new window

0
jknj72Author Commented:
"So, on your database, SUPPORTWEBSITE is a columnName and it has a value of www.abc123.com?"
That is correct....

Results....
NavigateUrl='<%# Eval("ID","SUPPORTWEBSITE") %>

This is what I had earlier and like I said its pointing to the Column Name again (SUPPORTWEBSITE) instead of the value www.abc123.com???
0
sammySeltzerCommented:
Oh yea. That's true; that won't work.

Since you have already have the url stored on the database, then you really don't need all the navigateURL stuff.

Simply use this:

                   <a href='<%#Eval("owner")%>'/>Text</a>

as in:

                <asp:TemplateField HeaderText="Web Site" SortExpression="SUPPORTWEBSITE">
                 <ItemTemplate>
                     <a Target="_blank" href='<%#Eval("SUPPORTWEBSITE")%>'/><%#Eval("SUPPORTWEBSITE")%</a>                 
                </ItemTemplate> 

Open in new window

               </asp:TemplateField>
0
sammySeltzerCommented:
Small error there:

 <asp:TemplateField HeaderText="Web Site" SortExpression="SUPPORTWEBSITE">
                 <ItemTemplate>
                     <a Target="_blank" href='<%#Eval("SUPPORTWEBSITE")%>'><%#Eval("SUPPORTWEBSITE")%</a>                 
                </ItemTemplate> 

Open in new window

0
jknj72Author Commented:
Getting an error that I was getting in the beginning. Seems to be requesting the website but with the folder my website before the url?

Error:
Requested URL: /Trans/www.assetworks.com/fa
0
sammySeltzerCommented:
What error are you getting exactly?

Also, on your database, how is the url stored?

Is it stored on same folder as the aspx file your gridview is on?

In other words, is the url stored on Trans folder?

If yes, are rest of your aspx files stored on same folder?
0
jknj72Author Commented:
Q: What error are you getting exactly?
A: Server Error in '/Trans' Application.
--------------------------------------------------------------------------------
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Trans/www.abc123.com/fa

 Q: Also, on your database, how is the url stored?
A: The url is stored as "www.abc123.com"

Q: Is it stored on same folder as the aspx file your gridview is on?
A: Is what stored in the same folder? The url is stored in Oracle in a table and I bring it back via a stored proc and load into gridview

Q: In other words, is the url stored on Trans folder?
A: No it is a value in a column in a table

Q: If yes, are rest of your aspx files stored on same folder?
A:  N/A but just so you know all of my aspx files are in the root folder of my web site


Quick question. Is there something that will strip the '/Trans/'
 from '/Trans/www.abc123.com/fa'

Also, how come when I click on one of my other links that start with http or https  like this 'https://esupport.com' it works fine. It only doesnt work if the www is there?


Let me know if you have any other questions.  Thanks
0
sammySeltzerCommented:
If you are storing in the db, I think you will to store with http://www.

In the meantime, can you try this:

       
         <a Target="_blank" href='<%# Eval("SUPPORTWEBSITE", "Trans/http://{0}.jpg")%>'><%#Eval("SUPPORTWEBSITE")%></a>

Open in new window


If that doesn't work, then try this:

         <a Target="_blank" href='<%# Eval("SUPPORTWEBSITE", "Trans/{0}.jpg")%>'><%#Eval("SUPPORTWEBSITE")%></a>

Open in new window

0

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
sammySeltzerCommented:
Sorry wrong code, I was just testing:

It should be:

                   <a Target="_blank" href='<%# Eval("SUPPORTWEBSITE", "Trans/{0}")%>'><%#Eval("SUPPORTWEBSITE")%></a>

Open in new window

0
jknj72Author Commented:
FYI, the Trans/ is part of the problem. I dont need to put it in front of the {0} especially since it has been part of the problem from the beginning. I want to just bring up the site, which is the value in the column. I dont want anything before it and I dont want anything after it, I just want to bring up the site, which is the value in the column. The value in the column is www.abc123.com and that is what I want to bring up, not Trans/www.abc123.com. I just want to bring up www.abc123.com
0
jknj72Author Commented:
I dont have time to try and figure out how to open the www so I fortunately have the ability to change the data for the website field so thats what I did. I didnt wanna have to do this unless it was the only way for this to work but I can deal with this..
0
jknj72Author Commented:
thanks
0
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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.