0

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:test@gmail.com">test@gmail.com</a>

user123456789
  • 1,914
  • 7
  • 44
  • 100
  • 1
    Perhaps you should look at [content editable divs](http://stackoverflow.com/questions/4705848/rendering-html-inside-textarea). – mason Dec 22 '16 at 16:48

1 Answers1

1

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.

Eric Burdo
  • 812
  • 1
  • 10
  • 24
  • You can use the code that @Fawzidi provided below to put into the Click event on the TextBox to send your email. But it still doesn't give you the HTML control to just click and send an email. – Eric Burdo Dec 23 '16 at 12:53