[英]How to launching email client on LinkButton click event?
如何啟動Outlook電子郵件窗口(類似於mailto:在超鏈接中執行的操作)?
這需要在LinkButton
點擊事件中完成。
考慮到mailto功能是需要在客戶端發生的功能。 你將需要javascript來做到這一點。 根據您希望mailto發生的時間,您有兩個選擇。
如果您希望在單擊LinkButton后立即發生,則只需添加到LinkButton
的OnClientClick
事件:
<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);
希望有所幫助。
我已經使用LinkButton的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';";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.