如何在 LinkBut​​ton 单击事件上启动电子邮件客户端?

发布于 2024-08-31 23:30:04 字数 96 浏览 7 评论 0原文

如何启动 Outlook 电子邮件窗口(类似于超链接中的 mailto: 功能)?

这需要在 LinkBut​​ton 点击事件中完成。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2024-09-07 23:30:04

考虑到 mailto 功能是需要在客户端发生的功能。你将需要 javascript 来完成它。根据您希望邮件发送的时间,您有两种选择。

如果您希望它在单击 LinkBut​​ton 后立即发生,则只需添加到 LinkBut​​tonOnClientClick 事件:

<asp:LinkButton runat="server" ID="btnEmail" Text="Send Email"
    OnClientClick="window.open('mailto:[email protected]','email');">
</asp:LinkButton>

如果您希望它在服务器端代码之后发生运行您将连接 javascript 事件以在新页面启动时运行:

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

希望有帮助。

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:[email protected]','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:[email protected]','email');", true);

Hope that helps.

蓦然回首 2024-09-07 23:30:04

我使用 LinkBut​​ton 的 OnClientClick 事件完成了此操作。

您可以使用:

<asp:LinkButton runat="server" ID="btnEmail" Text="Send Email"
    OnClientClick="window.location.href = 'mailto:[email protected]?subject=Email Subject';">
</asp:LinkButton>

您也可以在代码中执行此操作,以防您需要从数据库或其他内容加载电子邮件地址:

btnEmail.OnClientClick = "window.location.href = 'mailto:[email protected]?subject=Email Subject';";

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:[email protected]?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:[email protected]?subject=Email Subject';";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文