0
votes

I have an email that I am trying to send that contains a hyperlink which is supposed to open the target page in a new window or tab when clicked. However the problem I am having is there is no space between the querystring variable "item_id" and the "target" tag.

As you can see below the target is running onto the querystring variable thus causing a page error. This is how the link is formed in runtime.

http://www.mystore.com/item.aspx?id=1target='_blank'

I need to have the link look like this: http://www.mystore.com/item.aspx?id=1 target='_blank'

Below is the code I am using. In the quotation marks contain the "target", I have a space before "target". But the space is not there at runtime.

Dim viewLink As String

viewLink="<a href=" + "http" + "://www.mystore.com/item.aspx?id=" + item_id + " target=" + "_blank" + ">" + "View Item" + "</a>" + "<br/><br/>"

Can anyone tell me how to fix this?

1
You are unnecessarily breaking-up your string. - Dai
Also your generated HTML is missing required quotes around attribute values. - Dai

1 Answers

0
votes

Use String.Format to be clearer, and put spaces in your strings. and use "" to have VB write a single double-quote character.

Dim viewLink as String = String.Format( _
    "<a href=""http://www.mystore.com/item.aspx?id={0}"" target=""_blank"">View Item</a><br /><br />", _
    item_id _
)

This will render like this:

<a href="http://www.mystore.com/item.aspx?id=123" target="_blank">View Item</a><br /><br />

That said, links in emails will generally always open in a new window, regardless of e-mail client used (e.g. desktop Outlook, GMail, etc), so adding an explicit target="_blank" is unnecessary.