Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set asp:HyperLink href to "mailto:[email protected]" in .net c#

Tags:

c#

asp.net

Does anyone know how can I set the asp:HyperLink href to "mailto:[email protected]" in .net c#?

Example: If I have the following code:

  <tr>
    <td class="graytext r">PERSONAL EMAIL:</td>
    <td><asp:HyperLink runat="server" ID="sPersonalEmail" class="orange" style="cursor:pointer" /></td>
  </tr>

How can I set the href to "mailto:[email protected]" in .net c# instead of hard code it in asp:HyperLink?

like image 422
Jin Yong Avatar asked Sep 09 '11 04:09

Jin Yong


2 Answers

Something like this by setting NavigateUrl:

<asp:HyperLink runat="server" NavigateUrl='<%# Bind("Email", "mailto:{0}") %>'
                              Text='<%# Bind("Email") %>'
                              ID="hlEmail">
</asp:HyperLink>
like image 191
Pranay Rana Avatar answered Oct 25 '22 14:10

Pranay Rana


I find this the easiest

string whateverEmail = "[email protected]";

hypEmail.Attributes.Add("href", "mailto:" + whateverEmail );
like image 3
Andrew Avatar answered Oct 25 '22 14:10

Andrew