Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 28th, 2007, 12:00 AM
Registered User
 
Join Date: Jun 2007
Location: hyd, ap, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default using Page.RenderControl()

I have a webpage which is displayed a series of times with different controls each time.

I have a function which has the code to generate the controls dynamically which is a called in the next button.

Now my requirement is that, whenever the user clicks the next button I have to capture the current page with the controls and the data in it (static) in the form of pdf file and finally at the last when the user clicks the submit button I have to merge the pdf files and pop it up .

To generate the pdf I am using a third party dll which needs html source of the page so to get that i am using the following code

protected void ExportToPDF()
{
try
{

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
Page.RenderControl(oHtmlTextWriter);
oHtmlTextWriter.Flush();


string pageSoure = oStringWriter.ToString();
oHtmlTextWriter.Close();

PdfConverter pdfcon = new PdfConverter();
pdfcon.LicenseFilePath = Server.MapPath("Bin/");
pdfcon.PageWidth = 900;
pdfcon.PdfDocumentOptions.LeftMargin = 25;
pdfcon.PdfDocumentOptions.RightMargin = 25;
pdfcon.AvoidTextBreak = true;
pdfcon.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape;
pdfcon.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfcon.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfcon.SavePdfFromHtmlStringToFile(pageSoure, Request.PhysicalApplicationPath + @"\temp\" + pageID.ToString() + ".pdf");

pageSoure = "";

}
catch
{}
}

here I am using a third party dll to convert to pdf ....now wen i call this function in the next button I am getting an http error as "A page can have only one server-side Form tag."

Please help me regarding this .

Thanks in advance

Reply With Quote
  #2 (permalink)  
Old June 8th, 2011, 02:06 AM
Registered User
 
Join Date: Jun 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, i have the same problem. The only difference is that i started by a sample program from here:http://www.voip-sip-sdk.com/p_159-ho...urce-voip.html


Maybe you can find the mistake here - i couldn't
Reply With Quote
  #3 (permalink)  
Old May 26th, 2014, 04:26 AM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: using Page.RenderControl()

Hi, try overriding the VerifyRenderingInServerForm method, like the following:
Code:
public override void VerifyRenderingInServerForm(Control control)
{ }
That worked for me and I hope it will help anyone that encounters this issue. Also I used a different third party component, this Word DLL written in C#, here is how you can try it out:
Code:
protected void ExportToPDF()
{
	System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
	System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
	Page.RenderControl(oHtmlTextWriter);
	string pageSoure = oStringWriter.ToString();

	DocumentModel document;
	HtmlLoadOptions option = new HtmlLoadOptions() { BaseAddress = this.Request.PhysicalApplicationPath };
	using (Stream htmlStream = new System.IO.MemoryStream(option.Encoding.GetBytes(pageSoure)))
		document = DocumentModel.Load(htmlStream, option);

	PageSetup page = document.Sections[0].PageSetup;
	page.PageWidth = 900;
	page.PageMargins.Left = 25;
	page.PageMargins.Right = 25;
	page.Orientation = Orientation.Landscape;
	page.PaperType = PaperType.A4;
	
	document.Save(Request.PhysicalApplicationPath + @"\temp\" + pageID.ToString() + ".pdf");
}
In one of my previous project I used it to convert HTML files (from various sources) into PDF files through C#. Also before showing them I needed to join these multiple files (this can also be easily done in this DLL with import method) and then export the generated PDF to an ASP.NET client.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
access C#.Net page as action of calssic ASP page mansharma_s ASP.NET 1.x and 2.0 Application Design 6 January 7th, 2008 09:58 AM
RenderControl and Render methods joxa83 ASP.NET 1.x and 2.0 Application Design 4 August 24th, 2006 08:10 AM
Using rendercontrol with parameters? shenku C# 2 October 13th, 2005 09:21 AM



All times are GMT -4. The time now is 12:55 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.