View Full Version : How to create link in asp

11-28-2006, 02:08 PM
I am using a event listing applicatio which has database running at backend. I have made the field "feature1" in db as hyperlink and its working fine but this field does not show up as hyperlink on the viewing page...what can I change so that it does come up as hyperlink....thanks

I want the "contact" field to show up as hyperlink. the variable for it is Feature1

The code in asp file for this is
<% If eventlist.Fields.Item("Feature1").Value <> "" Then %>
<td width="80" valign="top" class="tableheader"><div align="right">Contact: </div>
<td valign="top" bgcolor="#FFFFCC"><%=Replace(eventlist.Fields.Item("Feature1").Value,Chr(13),"<BR>")%></td>
<% End If%>

11-29-2006, 02:58 AM
You need to use Anchor tag whenever you create a link in HTML. Refer the following code piece

Dim href
Dim title

href = "http://www.google.com" 'The url of the site
title = "Visit Google" ' The title you want to use

Response.Write("<a href='"& href &"' target='_blank'>" & title & "</a>")

In the above code snippet you've stored the actual url in a variable href and the title you want to show in title variable. The Response.Write() does the hyperlink writing which is self explanatory.

Dim href
Dim title

href = "http://www.yahoo.com" 'The url of the site
title = "Yahoo!" ' The title you want to use

Dim hyperlink: hyperlink = "<a href='"& href &"' target='_blank'>" & title & "</a>" 'complete anchor tag in a variable

Response.Write("<br>"&hyperlink) 'Hyperlink construction

In the above code snippet the variable part is almost similar in the first code snippet except a major difference, here we stored the entire anchor tag inside a variable and wherever we need the hyperlink we just used it using Response.Write()

In your case you can retrieve the hyperlink (url) value from your database and specify that in place of the href attribute of anchor tag as well as if you want you can specify it as the caption of the anchor tag.