Jump to content

Mail current web page


jteixeira

Recommended Posts

Have you tried the solution you posted here: http://w3schools.invisionzone.com/index.ph...ost&p=66685Rather than calling RenderControl on the GridView object, have you tried calling it on the Page? I don't know if it'll work, but you might try it:

StringWriter writer = new StringWriter();HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);Page.RenderControl(htmlWriter);return writer.toString();

Link to comment
Share on other sites

put a hidden <asp:textbox> in your page "txtSource" then place the following script just before </body>

<script type="text/javascript">  document.getElementById("txtSource").value = "<html>" + document.getElementsByTagName("html")[0].innerHTML + "</html>";</script>

Then when you press the email send button you can use txtSource.Text to get the full html code to paste into the message body

Link to comment
Share on other sites

What about calling Render() on the Page instead of RenderControl()? If I had more time at the moment I'd play around with this but for now I just have to toss you ideas and hope they work! :)

StringWriter writer = new StringWriter();HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);Page.Render(htmlWriter);return writer.toString();

Link to comment
Share on other sites

error: Server Error in '/1' Application.--------------------------------------------------------------------------------A potentially dangerous Request.Form value was detected from the client (TextBox1="<html><HEAD><TITLE>U...").
Hah, the HttpRequestValidationException. I was just working with that yesterday. To allow HTML to be submitted to your form, set the ValidateRequest="true" in the page declaration:
<%@ Page Language="C#" CodeFile="MyPage.aspx.cs" Inherits="MyPage" ValidateRequest="false" %>

But, before you do that, try calling Page.Render(htmlWriter) rather than Page.RenderControl(htmlWriter) like I posted above.

Link to comment
Share on other sites

It works :) thanks
Which method worked? Setting the page contents to the value of a text box and emailing that? Or calling the Render method on the Page?
Link to comment
Share on other sites

I'm using 1.1 (at work) and there is no Page.Render only Page.RenderControl I'll have to check whne I get home (I have 2.0 at home) to see if it is there.
We use 2.0 here at work and it is there but I haven't ever fiddled with it. I know there's gotta be a way to render a page on the server to get its contents. I just haven't tested that Page.Render() method.Another alternative could be something like this:
string url = "http://www.w3schools.com/default.asp";System.Net.WebClient client = new System.Net.WebClient();string html = client.DownloadString(url);

But I just have to think that there should be a way to get the rendered contents of an aspx page without having to resort to an HTTP request.

Link to comment
Share on other sites

I guess if Render is only available in 2.0 and up and if you are in 1.1, you might try putting the page display in a control and then use your RenderControl method:

<asp:Panel id="PageContentPanel" runat="server"><!-- Page contents go here --></asp:Panel>

Then, in the code:

StringWriter writer = new StringWriter();HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);PageContentPanel.RenderControl(htmlWriter);return writer.toString();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...