how to create mailto link in text box?

1.1k views Asked by At

I have a textbox that shows the user's email address and I want to add a mailto link to the textbox. So when I click on the textbox it will automatically open outlook.

 <asp:TextBox runat="server" ID="txtContactEmail" ></asp:TextBox>

In the code behind I tried adding an a href link to the textbox:

 txtContactEmail.Text = "<a href=\"/mailto:" + bh.Email + "\">" + bh.Email + "</a>";

But it just displayed all the text instead of a link in the textbox - <a href="/mailto:[email protected]">[email protected]</a>

1

There are 1 answers

1
Eric Burdo On

The TextBox isn't designed to work that way. It doesn't parse or render HTML. It renders text exactly as it's entered.

I see two options.

1) Add code to the Click event of the TextBox to send the email. 2) Add a ASP:Literal control, and put your HTML MailTo: link into that. That would then render the HTML in a way that you can click the link.

You can do either of these with code-behind (C#) or with jQuery/Javascript.