Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I've created a link on an asp.net page that opens an email client. I would then like the page, or elements of the page to be appended to the body of the email. Debugging the code below the PageResult variable renders the html correctly. I wonder if it is possible to somehow use the PageResult variable in the mailto code also posted below, specifically in the body part of the statement.

Cheers

A

C#
        protected override void Render(HtmlTextWriter writer)
        {

            // *** Write the HTML into this string builder

            StringBuilder sb = new StringBuilder();

            StringWriter sw = new StringWriter(sb);



            HtmlTextWriter hWriter = new HtmlTextWriter(sw);

            base.Render(hWriter);



            // *** store to a string

            string PageResult = sb.ToString();



            // *** Write it back to the server

            writer.Write(PageResult);

}


ASP.NET
<td>
                <asp:HyperLink ID="HyperLink1"  A href="mailto: &Subject=Services Quote&body='<%#PageResult %>'" runat="server">Email Quote</asp:HyperLink>

            </td>

Doesn't seem to work.
Posted
Updated 31-Jan-12 13:13pm
v4

1 solution

The most likely thing to do, is to email the content you are rendering, if you can access that content outside the page. However, if you override the Render method of a page, you can capture the HTML of the page, and use that for your email.
 
Share this answer
 
Comments
Andrew Chambers 31-Jan-12 17:18pm    
Hi Christian and Others,

I've made some progress on this but still need a further prodding. I have a link on my page 'email quote'. When I press this button I would like the webpage to be placed into the body of the users email client to be sent to a customer. I've updated the question above with the code I have found which I believe acheives some of this.

Thanks
Christian Graus 31-Jan-12 19:37pm    
Looks to me like your remaining issue is two fold. First of all, possible issues between when the event is called and when the property tries to read the value, and second, you're trying to reference a local variable. Create a variable that is visible to the page, as a property, and if that does not work, I think you need to store it in the session as it loads, and refresh the page to set the values and send the mail.
Andrew Chambers 7-Feb-12 21:14pm    
"Create a variable that is visible to the page, as a property."
Hi Christian I thought I had done this already with PageResult being a class variable (not shown in the code.).

With the code I have above. And <%#PageResult %> in the mailto statement, Outlook does not even open when the link is pressed.Whereas without it, it opens.Thanks
Christian Graus 7-Feb-12 21:22pm    
string PageResult = sb.ToString(); This creates a new one, even if there's one as a member.
Andrew Chambers 7-Feb-12 21:29pm    
so are you saying just have
PageResult = sb.ToString();
If I have a class variable like so
String PageResult;
If so I have done this already and there is no change in the outcome.

Cheers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900