2

I want to use an asp.net button to launch an outlook window using the following html.

<a href="mailto:[email protected]?subject=Insurance Text">

What do I need to do to file html code from my onClick event?

1
  • Can I ask why a button and not just the anchor? Commented Oct 4, 2012 at 19:23

3 Answers 3

2

Try this

<asp:Button runat="server" 
            ID="btn" 
            OnClientClick="document.location = 'mailto:[email protected]?subject=Insurance Text'; return false;"
            Text="Mail" />
Sign up to request clarification or add additional context in comments.

Comments

1

There are two approaches. If you want the standard button, you could use something like this:

<asp:Button ID="MailToButton"
            Text="Send Email"
            OnClientClick="javascript: navigate('mailto:[email protected]'); return false;"
            runat="server" />

EDIT 2: Never mind about the UseSubmitBehavior property - I was incorrect. You'll just have to use return false;. Apparently ASP.NET does not render a regular non-submit button. How to disable postback on an asp Button

If you want an anchor tag, you can just use the NavigateUrl property of the Hyperlink tag:

<asp:HyperLink ID="MailToHyperlink"
               Text="Send Email"
               NavigateUrl="mailto:[email protected]"
               runat="server" />

You cannot launch Outlook from the standard click event in the code behind, however. The code behind click event occurs on the server, not on the client's machine, so whatever you do it needs to happen on the client's machine either through standard HTML or through javascript.

Comments

0

Why an ASP.NET button? Just use a simple HTML button.

They are plenty of example on the web. This one should work: using mailto button click event

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.