6

How can I launch an Outlook email window (similar to what mailto: does in a hyperlink) ?

This needs to be done in a LinkButton click event.

Kelsey
  • 47,246
  • 16
  • 124
  • 162
user279521
  • 4,779
  • 21
  • 78
  • 109

2 Answers2

12

Consider that the mailto functionality is a function that needs to happen client side. You are going to need javascript to do it. Depending on when you want the mailto to happen you have two choices.

If you want it to happen as soon as the LinkButton is clicked then just add to the LinkButton's OnClientClick event:

<asp:LinkButton runat="server" ID="btnEmail" Text="Send Email"
    OnClientClick="window.open('mailto:someone@somewhere.com','email');">
</asp:LinkButton>

If you want it to happen AFTER the server side code has run your are going to have wire up the javascript event to run when the new page starts up:

// At the end of your LinkButton server side OnClick event add the following code:
ClientScript.RegisterStartupScript(this.GetType(), "FormLoading",
    "window.open('mailto:someone@somewhere.com','email');", true);

Hope that helps.

Kelsey
  • 47,246
  • 16
  • 124
  • 162
  • well, there is an if statement that needs to execute in the LinkButtons code behind, so this (start a new email) will have to be in the code behind as an "else" condition; – user279521 May 10 '10 at 18:19
0

I've accomplished this using the OnClientClick event of the LinkButton.

You can use:

<asp:LinkButton runat="server" ID="btnEmail" Text="Send Email"
    OnClientClick="window.location.href = 'mailto:someone@something.com?subject=Email Subject';">
</asp:LinkButton>

You can also do this in code, in case you need to load an email address from a database or something:

btnEmail.OnClientClick = "window.location.href = 'mailto:someone@something.com?subject=Email Subject';";
Dave Patrick
  • 278
  • 3
  • 8