ASP:HyperLink & Mailto

Recently I had a bit of trouble getting the HyperLink control to push out a mailto link in a Details View.

<asp:HyperLink NavigateUrl=’mailto:’ Text=’<%# Bind(”Email”) %> runat=”server” ID=”hlEmail”></asp:HyperLink>

 

This leaves a hyperlink but with a blank mailto - i.e. test@techtoolblog.com

So I assume if I stick in the bind (or eval) text to the Navigate URL we should be good to go:

<asp:HyperLink NavigateUrl=’mailto:<%# Bind(”Email”) %> Text=’<%# Bind(”Email”) %> runat=”server” ID=”hlEmail”></asp:HyperLink>

 

This gives me a link that is NOT clickable - If I view the source I see

<a id=”Details_hlEmail” href=”mailto:&lt;%#%20Bind(&quot;Email&quot;)%20%>”>test@techtoolblog.com </a>

 

My next guess is that this has something to do with formatting string, sure enough it is: This is the solution that ended up working for me:

<asp:HyperLink NavigateUrl=’<%# Bind(”Email”, “mailto:{0}”) %> Text=’<%# Bind(”Email”) %> runat=”server” ID=”hlEmail”></asp:HyperLink>

Written by Tim on August 15th, 2007 with 2 comments.
Read more articles on asp.net.



Related articles

2 comments

Read the comments left by other users below, or:

Get your own gravatar by visiting gravatar.com Carsten
#1. May 13th, 2008, at 10:03 AM.

Thank you for this code. It helped me a lot. Superb !

Get your own gravatar by visiting gravatar.com laptop batteries
#2. November 4th, 2008, at 12:51 AM.

dell t6840 battery

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> .