开发者

how to set asp:HyperLink href to "mailto:abc@hotmail.com" in .net c#

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?


Something like this by setting NavigateUrl:

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


I find this the easiest

string whateverEmail = "test@this.com";

hypEmail.Attributes.Add("href", "mailto:" + whateverEmail );


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;


Another way is this:

<asp:BoundField DataField="Email" DataFormatString="<a href=mailto:{0}>{0}</a>" HtmlEncodeFormatString="false" />


This is my ASP.NET code using the asp:HyperLink properties.

 hlEmail.Text = "theEmail@webAddess.com";
 hlEmail.NavigateUrl = "mailto:" + "theEmail@webAddess.com";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜