Jump to content
Sign in to follow this  
jteixeira

Mail current web page

Recommended Posts

hi, i'm workin with visual web developer in c# and i have a page and i want that when i click in button, the page has mailed, not the link the page with the texboxes, label everything

Share this post


Link to post
Share on other sites

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();

Share this post


Link to post
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

Share this post


Link to post
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();

Share this post


Link to post
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...").

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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();

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...