send entire page by email

Discussion in 'ASP .Net' started by Martin, Apr 13, 2005.

  1. Martin

    Martin Guest

    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.
    Martin, Apr 13, 2005
    #1
    1. Advertising

  2. 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

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net




    "Martin" <> wrote in message
    news:%...
    > 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.
    >
    >
    >
    Steve C. Orr [MVP, MCSD], Apr 13, 2005
    #2
    1. Advertising

  3. 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]" <> ¦b¶l¥ó
    news:up% ¤¤¼¶¼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
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD, MVP
    > http://SteveOrr.net
    >
    >
    >
    >
    > "Martin" <> wrote in message
    > news:%...
    > > 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.
    > >
    > >
    > >

    >
    >
    Lau Lei Cheong, Apr 13, 2005
    #3
  4. Martin

    Martin Guest

    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" <> wrote in message
    news:%23Xr%...
    > 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]" <> ¦b¶l¥ó
    > news:up% ¤¤¼¶¼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
    >>
    >> --
    >> I hope this helps,
    >> Steve C. Orr, MCSD, MVP
    >> http://SteveOrr.net
    >>
    >>
    >>
    >>
    >> "Martin" <> wrote in message
    >> news:%...
    >> > 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.
    >> >
    >> >
    >> >

    >>
    >>

    >
    >
    Martin, Apr 13, 2005
    #4
  5. Martin

    Martin Guest

    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.








    "Steve C. Orr [MVP, MCSD]" <> wrote in message
    news:up%...
    > 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
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD, MVP
    > http://SteveOrr.net
    >
    >
    >
    >
    > "Martin" <> wrote in message
    > news:%...
    >> 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.
    >>
    >>
    >>

    >
    >
    Martin, Apr 13, 2005
    #5
  6. 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" <> ¦b¶l¥ó
    news: ¤¤¼¶¼g...
    > 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" <> wrote in message
    > news:%23Xr%...
    > > 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]" <> ¦b¶l¥ó
    > > news:up% ¤¤¼¶¼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
    > >>
    > >> --
    > >> I hope this helps,
    > >> Steve C. Orr, MCSD, MVP
    > >> http://SteveOrr.net
    > >>
    > >>
    > >>
    > >>
    > >> "Martin" <> wrote in message
    > >> news:%...
    > >> > 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.
    > >> >
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Lau Lei Cheong, Apr 13, 2005
    #6
  7. Martin

    Martin Guest

    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" <> wrote in message
    news:OrBtEC%...
    > 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" <> ¦b¶l¥ó
    > news: ¤¤¼¶¼g...
    >> 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" <> wrote in message
    >> news:%23Xr%...
    >> > 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]" <> ¦b¶l¥ó
    >> > news:up% ¤¤¼¶¼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
    >> >>
    >> >> --
    >> >> I hope this helps,
    >> >> Steve C. Orr, MCSD, MVP
    >> >> http://SteveOrr.net
    >> >>
    >> >>
    >> >>
    >> >>
    >> >> "Martin" <> wrote in message
    >> >> news:%...
    >> >> > 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.
    >> >> >
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    Martin, Apr 13, 2005
    #7
  8. 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" <> ¦b¶l¥ó
    news:%23245EM% ¤¤¼¶¼g...
    > 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" <> wrote in message
    > news:OrBtEC%...
    > > 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" <> ¦b¶l¥ó
    > > news: ¤¤¼¶¼g...
    > >> 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" <> wrote in message
    > >> news:%23Xr%...
    > >> > 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]" <> ¦b¶l¥ó
    > >> > news:up% ¤¤¼¶¼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
    > >> >>
    > >> >> --
    > >> >> I hope this helps,
    > >> >> Steve C. Orr, MCSD, MVP
    > >> >> http://SteveOrr.net
    > >> >>
    > >> >>
    > >> >>
    > >> >>
    > >> >> "Martin" <> wrote in message
    > >> >> news:%...
    > >> >> > 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.
    > >> >> >
    > >> >> >
    > >> >> >
    > >> >>
    > >> >>
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
    Lau Lei Cheong, Apr 13, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter
    Replies:
    0
    Views:
    3,336
    Peter
    Jul 1, 2003
  2. Replies:
    2
    Views:
    385
    Tintin
    Jan 5, 2007
  3. Replies:
    13
    Views:
    447
    Randy Webb
    May 14, 2006
  4. pbd22
    Replies:
    1
    Views:
    138
  5. ashish makani
    Replies:
    5
    Views:
    563
    Mark Lawrence
    Sep 20, 2012
Loading...

Share This Page