2011-09-09 15 views
10

Qualcuno sa come posso impostare l'asp: HyperLink href a "mailto: [email protected]" in .net C# ?come impostare asp: HyperLink href a "mailto: [email protected]" in .net C#

Esempio: Se ho il seguente codice:

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

Come posso impostare il href di "mailto: [email protected]" in .net C#, invece di codificare in asp: HyperLink ?

+2

quello che hai provato e quali risultati hai ottenuto? –

risposta

7

Qualcosa di simile impostando NavigateUrl:

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

Trovo che questo sia il modo più semplice

string whateverEmail = "[email protected]"; 

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

Non dimenticare di aggiungere questa riga: hypEmail.Text = whateverEmail; –

1

Se si voleva farlo codice dietro, allora si può semplicemente mettere le seguenti nel caricamento della pagina (o ove rilevante, come un evento del pulsante):

string email = "[email protected]"; sPersonalEmail.NavigateUrl = "mailto:" + email;

1

Un altro modo è questo:

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