From my experience, don't use window.location to attract an email client and redirect to the same page - this is a beast. Instead, use the form to send email using the System.Net.Mail namespace and the objects in it, and then redirect your email. If this is not an option, store the mailto data in a session, redirect and then call the mail client when the page loads. The only caveat about this approach is that window.location will kill any responses that were not written, so you will need to give the page some time to load using a timer event, usually around 2000 milliseconds (if your page has dynamic data and has different loading times, good luck!).
This piece of code uses jQuery to wait for the document to be ready for use, and will add 2,000 milliseconds to record any responses.
function showEmailClient(mailto) { $(document).ready(function () { setTimeout(function () { window.location = mailto; }, 2000); }); } protected void Page_Load(object sender, EventArgs e) { if (Session["SendMail"] != null) { var mailto = Session["SendMail"].ToString(); ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ShowEmailClient", "showEmailClient('" + mailto + "');", true); Session["SendMail"] = null; } }
source share