Search code examples
asp.netliteralsmailto

mailto and literal control together


Is it possible to do this and how?

email: <a href="" mailto:""email1""">
         <asp:Literal ID="email1" runat="server" >
         </asp:Literal>
       </a> <br />

I try this but when I open outlook it doesn't write anything in TO: section.


Solution

  • If your application is running under .net 3.5;

    email:<a href="mailto:<%= Server.HtmlEncode(email1.Text) %>"><asp:Literal Text="[email protected]" ID="Literal1" runat="server"/></a><br/>
    

    If your application is running under .net 4;

    email:<a href="mailto:<%: email1.Text%>"><asp:Literal ID="email1" Text="[email protected]" runat="server"/></a><br/>
    

    NOTE:
    although you can use the first approach on .net 4 as well, it's better to use the second one in order to avoid so called syntactic noise

    hope this helps.