2011-09-09 19 views
10

¿Alguien sabe cómo puedo configurar el asp: HyperLink href a "mailto: [email protected]" en .net C# ?cómo configurar asp: HyperLink href a "mailto: [email protected]" en .net C#

Ejemplo: Si tengo el siguiente código:

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

¿Cómo puedo establecer el href a "mailto: [email protected]" en .NET C# en lugar de codificar en asp: HyperLink ?

+2

¿Qué usted intentó y que resulte obtuvo? –

Respuesta

7

Algo como esto estableciendo NavigateUrl:

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

Me parece el más fácil

string whateverEmail = "[email protected]"; 

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

No olvide agregar esta línea: hypEmail.Text = whateverEmail; –

1

Si quisiera hacerlo código detrás entonces se podría simplemente poner el siguiente en la carga de la página (o cuando sea relevante, como un evento de botón):

string email = "[email protected]"; sPersonalEmail.NavigateUrl = "mailto:" + correo electrónico;

1

Otra forma es la siguiente:

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