jteixeira Posted April 17, 2007 Share Posted April 17, 2007 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 Link to comment Share on other sites More sharing options...
jesh Posted April 17, 2007 Share Posted April 17, 2007 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 More sharing options...
jteixeira Posted April 18, 2007 Author Share Posted April 18, 2007 it dosen't work error in "Page.RenderControl(htmlWriter);" -> RegisterForEventValidation can only be called during Render(); Link to comment Share on other sites More sharing options...
aspnetguy Posted April 18, 2007 Share Posted April 18, 2007 try setting EnableEventValidation = "false" on your page declaration. Link to comment Share on other sites More sharing options...
jteixeira Posted April 18, 2007 Author Share Posted April 18, 2007 The same error Link to comment Share on other sites More sharing options...
aspnetguy Posted April 18, 2007 Share Posted April 18, 2007 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 More sharing options...
jesh Posted April 18, 2007 Share Posted April 18, 2007 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 More sharing options...
jteixeira Posted April 18, 2007 Author Share Posted April 18, 2007 error: Server Error in '/1' Application.--------------------------------------------------------------------------------A potentially dangerous Request.Form value was detected from the client (TextBox1="<html><HEAD><TITLE>U..."). Link to comment Share on other sites More sharing options...
aspnetguy Posted April 18, 2007 Share Posted April 18, 2007 in your page declaration set ValidateRequest="false" Link to comment Share on other sites More sharing options...
jesh Posted April 18, 2007 Share Posted April 18, 2007 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 More sharing options...
jteixeira Posted April 18, 2007 Author Share Posted April 18, 2007 It works thanks Link to comment Share on other sites More sharing options...
jesh Posted April 18, 2007 Share Posted April 18, 2007 It works thanksWhich 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 More sharing options...
aspnetguy Posted April 18, 2007 Share Posted April 18, 2007 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. Link to comment Share on other sites More sharing options...
jesh Posted April 18, 2007 Share Posted April 18, 2007 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 More sharing options...
jesh Posted April 18, 2007 Share Posted April 18, 2007 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now