Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

c# - How to launching email client on LinkButton click event?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...