2010-05-10 56 views

回答

11

考慮到mailto功能是需要發生客戶端的功能。你將需要JavaScript來做到這一點。根據你想要發送郵件的時間,你有兩種選擇。

如果你想讓它儘快LinkBut​​ton的點擊結果,那麼只需添加到LinkButtonOnClientClick事件:

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

如果你希望它發生在服務器端代碼之後運行ARE在新的頁面啓動時將要啓動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); 

希望有所幫助。

+0

好,有一個if語句需要在後面的LinkBut​​tons代碼中執行,所以這(開始一個新的電子郵件)必須作爲「其他」條件落在代碼後面; – user279521 2010-05-10 18:19:44

+0

它的工作原理!但你已經知道:-) – user279521 2010-05-10 18:23:11

0

我已經使用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';"; 
相關問題