【问题标题】:How to launching email client on LinkButton click event?如何在 LinkBut​​ton 点击​​事件上启动电子邮件客户端?
【发布时间】:2011-02-17 18:19:26
【问题描述】:

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

这需要在LinkButton点击事件中完成。

【问题讨论】:

    标签: c# asp.net .net-3.5 email linkbutton


    【解决方案1】:

    我已经使用 LinkBut​​ton 的 OnClientClick 事件完成了这项工作。

    你可以使用:

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

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

    btnEmail.OnClientClick = "window.location.href = 'mailto:someone@something.com?subject=Email Subject';";
    

    【讨论】:

      【解决方案2】:

      认为 mailto 功能是需要在客户端发生的功能。您将需要 javascript 来执行此操作。根据您希望 mailto 发生的时间,您有两种选择。

      如果您希望在单击链接按钮后立即发生,只需添加到LinkButtonOnClientClick 事件:

      <asp:LinkButton runat="server" ID="btnEmail" Text="Send Email"
          OnClientClick="window.open('mailto:someone@somewhere.com','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:someone@somewhere.com','email');", true);
      

      希望对您有所帮助。

      【讨论】:

      • 嗯,有一个 if 语句需要在后面的 LinkBut​​tons 代码中执行,所以这个(开始一封新的电子邮件)必须在后面的代码中作为“else”条件;跨度>
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多