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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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:<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1c2dedcd4dedfd4f1c2dedcd4c6d9d4c3d49fd2dedc">[email protected]</a>','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:<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8dfee2e0e8e2e3e8cdfee2e0e8fae5e8ffe8a3eee2e0">[email protected]</a>','email');", true);
Hope that helps.
Method 2
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:<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2655494b434948436655494b43524e4f48410845494b">[email protected]</a>?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:<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6615090b030908032615090b03120e0f08014805090b">[email protected]</a>?subject=Email Subject';";
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0