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>
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.