Home | Advertising Info141 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Wednesday, January 22, 2025  


Building Hyperlinks in ASP




Often when using ASP or Active Server Pages you will find it necessary to
create Hyperlinks or email us links dynamically. People seem to act like this is some sort of mystical and complex process and they couldn't be farther from the truth. Like I keep telling everyone ASP is just dynamically created HTML and making a hyperlink is accomplished by mixing HTML tags with the ASP variables. It's very simple to make a hyperlink.

Here is an example where we have a variable that is a hyperlink. This variable could come from a database query, but in this example we just set it.

<%
MyHyperLink = "http://www.CJWSoft.com"
%>


Now to make a hyperlink on our ".asp" page we simply do this

<a href="<% =MyHyperLink %>"><% =MyHyperLink %></a>

or you could build the string and Response.Write it to the page if you like.
(we even have a response.write code generator that can help with that)

<% Response.Write("<a href=""" & MyHyperLink & """>" & MyHyperLink & "</a>") %>

Either way, the result would be this.

http://www.CJWSoft.com

To take this even further let's say our hyperlink info may not contain the "http://" info.
Here is a very simple example of testing for that and dealing with it.

<%
If InStr(LCase(MyHyperLink) ,"http://") = 0 Then
     MyHyperLink = "http://" & MyHyperLink
End If
%>

<a href="<% =MyHyperLink %>"><% =MyHyperLink %></a>

Basically we use the LCase function to make the hyperlink we are testing lowercase just in case "http://" was spelled using any capital letters. Then we use the InStr function to see if the string "http://" is in the hyperlink. If it is not we simply add it to it. In this case we are not taking into account the possibility of a "https://" secure hyperlink, but you get the general idea.



The next example is an email hyperlink.

<%
MyEmailAddress = "someone@somesite.com"
%>


To make an email hyperlink with that we simply do this.

<a href="mailto:<% =MyEmailAddress %>"><% =MyEmailAddress %></a>

or this

<% Response.Write("<a href=""mailto:" & MyEmailAddress & """>" & MyEmailAddress & "</a>") %>

Which results in this.

someone@somesite.com

The thing to remember about ASP is that an understanding of HTML tags is very important. A lot of people tend to put all their faith in their WYSIWYG editors and have no idea how to write HTML by hand. Take some helpful advice and learn HTML tags. You cant work with ASP and make anything worthwhile if you can not understand and write basic HTML. Your WYSIWYG editors can only take you so far.


 

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2025 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages help tutorial how to ASP Help ASP Tutorials ASP Programming ASP Code - ASP Free CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspclassifieds.com, www.powerasp.com,www.cjwsoft.com,www.aspphotogallery.com,www.codewanker.com,www.aspprotect.com,www.aspbanner.com