user616076
user616076

Reputation: 4001

Using an asp.net button to launch html code

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?

Upvotes: 2

Views: 1426

Answers (3)

JDB
JDB

Reputation: 25810

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.

Upvotes: 1

Bestter
Bestter

Reputation: 878

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

Upvotes: 0

yogi
yogi

Reputation: 19591

Try this

<asp:Button runat="server" 
            ID="btn" 
            OnClientClick="document.location = 'mailto:[email protected]?subject=Insurance Text'; return false;"
            Text="Mail" />

Upvotes: 2

Related Questions