I can’t seem to get a HyperLinkField to display & link to an email address, using either DataNavigateURLFormatString or even a separate field, to provide the ‘mailto:’ part
Question:
I have used HyperlinkFields before to display text from one field in a database whilst linking to the value held in another field. This has worked well with relative http links, e.g. /MyPage.aspx.
I would now like to use one to provide a clickable link to an email address. Of course, I am not storing the link protocol (mailto:) with the email addresses, so I need to add this on the web page, so the link doesn’t try to link relatively to http://www.mywebsite.com/currentfolderpath/Paul.Cutcliffe@somewhere.com.
Reading the documentation, I see that Microsoft have already thought to this & provided us with the DataNavigateUrlFormatString property, & the example they provide works well: page.aspx?id={0} provides a link to http://www.mywebsite.com/currentfolderpath/page.aspx?id=Paul.Cutcliffe@somewhere.com.
However, when I apply this logic to my requirements & change the DataNavigateUrlFormatString property to mailto:{0} , my hyperlink ceases to be a hyperlink at all. Looking at the generated HTML, it does this: <td><a>Paul.Cutcliffe@somewhere.com</a></td> – so there’s a hyperlink, but it links to nowhere!
Does anyone know why this feature doesn’t work with mailto: ?
As a workaround, I thought I’d add another column to the View in the database called EmailLink, consisting of:
‘mailto:’ + dbo.aspnet_Membership.Email
… which of course is the URL I want to link to. Then I set the DataNavigateUrlFields property to EmailLink, & the DataTextField property to Email. However, the result is the same – the email address looks like plain text rather than a hyperlink, although behind the scenes again there is a hyperlink linking to nowhere.
So does anyone know how I can make these email links work?
Thanks.
Solution:
Ahh yes, this article should explain it for you, and a workaround.
http://scottonwriting.net/sowblog/posts/4830.aspx
Unfortunately you can’t use the HyperLinkField to do this…













Comments (0)
Trackbacks - Pingbacks (0)
Leave a Reply