send entire page by email

M

Martin

Hi,

I have a standard aspx page (form) that contains a few user controls.
Upon form submission the page is validated.
If validation passses then a text based email is sent.
This is all working fine, however what I would like to do is sent the entire
contents of the posted back page as a HTML email.

Is this possible and if so could somebody point me in the right direction to
achieving this.

many thanks in advance.

cheers

martin.
 
L

Lau Lei Cheong

Actually, emailing the content produced by Page.Render() will do the job if
the page you want to email is the page itself. And it would be a lot
simpler.
 
M

Martin

Hi Lau,

I called page.render from a button click on the page.
I used the following code.

Dim sb As New StringBuilder
Dim sw As New StringWriter
Dim htmlWriter As New HtmlTextWriter(sw)
Me.Render(htmlWriter)


I got an error saying "The page can only have one server-side form tag"
I guess the page thinks it is being rendered twice.

do you have any suggestions??

cheers

martin.
 
M

Martin

Hi steve,

I look at the 4guys article, this seems to work fine if the control is a
datagrid.
If I make my own user control and put on instance of it on a page (called
SimpleControl1)
The user control only has a single text box on it

and use the following code

Dim sb As New StringBuilder
Dim sw As New StringWriter
Dim htmlWriter As New HtmlTextWriter(sw)
SimpleControl1.RenderControl(htmlWriter)

I get an error when I try to do a post back (the above code is in a button
on a PAGE not the user control) saying that

"Control 'SimpleControl1_TextBox1' of type 'TextBox' must be placed inside a
form tag with runat=server"

I am not quite sure why this does not happen with the datagrid in 4guys
example.

If you could offer any advice it would be appreciated.

ideally I would like to send the output of the entire page (including all
user controls).
perhaps I will have to use a third party componenet.


cheers

martin.
 
L

Lau Lei Cheong

I've also encountered your problem, it's thought to be the case when
Page.Render() render the page twice and counted the page's form tag twice.
But since my form is actually a report, I just hide the user-input
parts(i.e.: the whole<form runat="server"></form>) in a <asp:panel> and hide
it before the mail function's Page.Render() calls. Since everything inside a
Panel with .Visible set to false won't render, it won't case problem.
 
M

Martin

yes I see that your work around would work if you didn't need to get the
user input.
But in my case I actually want the user input so hiding the entire form in
an asp panel is not an option.

I am hoping to be able to retrive the HTML generated from the "re render"
event but I have been unsuccessful at present.

thanks for your help though.

cheers

martin.





Lau Lei Cheong said:
I've also encountered your problem, it's thought to be the case when
Page.Render() render the page twice and counted the page's form tag twice.
But since my form is actually a report, I just hide the user-input
parts(i.e.: the whole<form runat="server"></form>) in a <asp:panel> and
hide
it before the mail function's Page.Render() calls. Since everything inside
a
Panel with .Visible set to false won't render, it won't case problem.

Martin said:
Hi Lau,

I called page.render from a button click on the page.
I used the following code.

Dim sb As New StringBuilder
Dim sw As New StringWriter
Dim htmlWriter As New HtmlTextWriter(sw)
Me.Render(htmlWriter)


I got an error saying "The page can only have one server-side form tag"
I guess the page thinks it is being rendered twice.

do you have any suggestions??

cheers

martin.







Lau Lei Cheong said:
Actually, emailing the content produced by Page.Render() will do the
job
if
the page you want to email is the page itself. And it would be a lot
simpler.

"Steve C. Orr [MVP, MCSD]" <[email protected]> ¦b¶l¥ó
¤¤¼¶¼g...
You can email a page by using the WebRequest and MailMessage classes.

Here are a couple examples:
http://www.aspalliance.com/stevesmith/articles/dotnetemailwebsite.asp
http://aspnet.4guysfromrolla.com/articles/091102-1.aspx






Hi,

I have a standard aspx page (form) that contains a few user
controls.
Upon form submission the page is validated.
If validation passses then a text based email is sent.
This is all working fine, however what I would like to do is sent
the
entire contents of the posted back page as a HTML email.

Is this possible and if so could somebody point me in the right
direction
to achieving this.

many thanks in advance.

cheers

martin.
 
L

Lau Lei Cheong

Here's an article on how to disable form validation:
http://msdn.microsoft.com/msdnmag/issues/02/04/Valid/default.aspx

I've not tried it, but you may take a look.

I suspect that deleting all runat=server from the page may also work,
because it's known that the input tags will preserve it's content even if
you don't do anything on it to preserve it. Just that don't know it's by the
client-side or server-side. If it's done by server-side, it'll work and you
can still access the form values through Response.Form[].

Martin said:
yes I see that your work around would work if you didn't need to get the
user input.
But in my case I actually want the user input so hiding the entire form in
an asp panel is not an option.

I am hoping to be able to retrive the HTML generated from the "re render"
event but I have been unsuccessful at present.

thanks for your help though.

cheers

martin.





Lau Lei Cheong said:
I've also encountered your problem, it's thought to be the case when
Page.Render() render the page twice and counted the page's form tag twice.
But since my form is actually a report, I just hide the user-input
parts(i.e.: the whole<form runat="server"></form>) in a <asp:panel> and
hide
it before the mail function's Page.Render() calls. Since everything inside
a
Panel with .Visible set to false won't render, it won't case problem.

Martin said:
Hi Lau,

I called page.render from a button click on the page.
I used the following code.

Dim sb As New StringBuilder
Dim sw As New StringWriter
Dim htmlWriter As New HtmlTextWriter(sw)
Me.Render(htmlWriter)


I got an error saying "The page can only have one server-side form tag"
I guess the page thinks it is being rendered twice.

do you have any suggestions??

cheers

martin.







Actually, emailing the content produced by Page.Render() will do the
job
if
the page you want to email is the page itself. And it would be a lot
simpler.

"Steve C. Orr [MVP, MCSD]" <[email protected]> ¦b¶l¥ó
¤¤¼¶¼g...
You can email a page by using the WebRequest and MailMessage classes.

Here are a couple examples:
http://www.aspalliance.com/stevesmith/articles/dotnetemailwebsite.asp
http://aspnet.4guysfromrolla.com/articles/091102-1.aspx






Hi,

I have a standard aspx page (form) that contains a few user
controls.
Upon form submission the page is validated.
If validation passses then a text based email is sent.
This is all working fine, however what I would like to do is sent
the
entire contents of the posted back page as a HTML email.

Is this possible and if so could somebody point me in the right
direction
to achieving this.

many thanks in advance.

cheers

martin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top