Reputation: 43788
Does anyone know how can I set the asp:HyperLink href to "mailto:abc@hotmail.com" 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:abc@hotmail.com" in .net c# instead of hard code it in asp:HyperLink?
Upvotes: 13
Views: 15516
Reputation: 357
This is my ASP.NET code using the asp:HyperLink properties.
hlEmail.Text = "theEmail@webAddess.com";
hlEmail.NavigateUrl = "mailto:" + "theEmail@webAddess.com";
Upvotes: 1
Reputation: 176956
Something like this by setting NavigateUrl
:
<asp:HyperLink runat="server" NavigateUrl='<%# Bind("Email", "mailto:{0}") %>'
Text='<%# Bind("Email") %>'
ID="hlEmail">
</asp:HyperLink>
Upvotes: 9
Reputation: 101
Another way is this:
<asp:BoundField DataField="Email" DataFormatString="<a href=mailto:{0}>{0}</a>" HtmlEncodeFormatString="false" />
Upvotes: 1
Reputation: 1576
If you wanted to do it code behind then you could simply put the following in page load (or wherever relevant, such as a button event):
string email = "abc@hotmail.com"; sPersonalEmail.NavigateUrl = "mailto:" + email;
Upvotes: 1
Reputation: 221
I find this the easiest
string whateverEmail = "test@this.com";
hypEmail.Attributes.Add("href", "mailto:" + whateverEmail );
Upvotes: 4