Hello World
Hello World

Reputation: 57

Setting body text of mailto from asp.net code behind method

I have an ASP.NET button. If the user clicks this button, then it calls mailto, which opens the outlook mail window. I have done this by adding the following line into the ASP.net button control tag.

window.open('mailto: abc def<[email protected]>?subject= exSub &body= exBody');

Now I want to set the body text (in the above example it is exBody) dynamically in my code behind method. How can I do that?

Upvotes: 0

Views: 6834

Answers (2)

McGarnagle
McGarnagle

Reputation: 102793

Bind it to a page property, and use the property to construct the mailto attribute (URL-encoded):

<asp:Button RunAt = "Server"
    onclick = <%# 
        "window.open('mailto: abc def<[email protected]>?subject= exSub &body="
        + Server.UrlEncode(MailToBody ?? "") + "');"
    %>
/>

Then set the MailToBody property from your code-behind as needed.

Upvotes: 1

Akash KC
Akash KC

Reputation: 16310

You can register script in Click event of button in codebehind following way:

 string mailBody = getMailBody(); //// Get the content for email body
 ClientScript.RegisterStartupScript(this.GetType(), "mailto",
        "window.open('mailto: abc def<[email protected]>?subject= exSub &body= "+ mailBody +"');", true);

Upvotes: 5

Related Questions