MyHeadHurts
MyHeadHurts

Reputation: 1562

use response write to make a link

I have a urlcolumn and a title column and i want the link to be automatically made in asp

 <td><%response.write(<a href="rs.fields.item("urlcolumn")target=_"blank">rs.fields.item("titlecolumn")</a>)%></td>

Upvotes: 0

Views: 5731

Answers (3)

thirtydot
thirtydot

Reputation: 228302

<td><%response.write("<a href=""" & rs.fields.item("urlcolumn") & """ target=""_blank"">" & rs.fields.item("titlecolumn") & "</a>")%></td>

Upvotes: 1

Tim M.
Tim M.

Reputation: 54417

At the minimum, you will need to quote the output value for Response.Write to work, i.e.

<td><%Response.Write("<a href='" + rs.fields.item("urlcolumn") + "' target='_blank'>" + rs.fields.item("titlecolumn") + "</a>")%></td>

EDIT (updated my code sample).

EDIT #2 - Make sure to clean any input going into these links. Creating links this way makes you very vulnerable to a XSS attack (especially since the href attribute can actually execute Javascript).

Upvotes: 1

Bobby D
Bobby D

Reputation: 2159

You could do what you are trying by string concatenation:

<%= Response.Write("<a href=\"" + rs.fields.item("urlcolumn") + "\" target=\"_blank\">" + rs.fields.item("titlecolumn") + "</a>") %>

However, you might be better served using an asp:HyperLink control.

Upvotes: 1

Related Questions