Okay so, I can send the current pages contents to email just fine, formatting it is a bit strange and ends up a little differently than expected, but I am getting the hang of it.
What I am currently wanting to do is to send and access a previous pages entire formatted form within the current one (I am thinking this can be done with a session object) and then send this to email. This includes user input into text boxes etc (which I am currently persisting across the pages via session objects [if this matters]).
I have tried to search google and this site with nothing that really solves these issues, and there are several of them.
If someone could point me in the right direction, it would be greatly appreciated.
For clarity, here is the process I am utilizing to send the current page via email:
StringWriter sw = new StringWriter( );
HtmlTextWriter w = new HtmlTextWriter( sw );
MAIN.RenderControl( w );
string s = sw.GetStringBuilder( ).ToString( );
MailMessage message = new MailMessage( );
message.IsBodyHtml = true;
message.To.Add( new MailAddress( Session["eMail"].ToString( ) ) );
message.Subject = "foo bar";
message.From = new MailAddress( "email@email.com" );
message.Body = s; //this would be filled with the previous page
So basically, the message.Body would be the form contents (formatted and with all user content) of a previous page.
Thanks in advance!
EDIT: I do not mean the literal previous page before the one you would currently be on, I mean a page that was previous in the process to getting to this page (in my case it is the second page in the process and the email will be sent at the fourth page).
if you know all the parameters your previous page was given, you can create an instance of your page and generate it’s HTML.
I’ve written a blog post about it here:
http://www.diaryofaninja.com/blog/2009/09/14/a-simple-solution-to-viewing-a-preview-of-any-page-in-your-site
Basically this means tapping into the ASP.Net runtime and executing the page through its lifecycle – if your page has any public properties such as content ID’s etc you can set them as part of this.
Obviously this is not getting the previous page, but instead generating it all over again and getting its content.