views:

116

answers:

2

We use ascx user controls as templates for documents (e.g. invoices). Now I need to load,render to HTML, then transform to PDF these controls from windows service.

So, what's the correct way/workaround? TemplateControl.LoadControl(path) doesn't work.

A: 

To be perfectly honest, I don't know how to do this. However, if I was stuck with this problem, I think I'd download the ASP.NET MVC source, and see what they do to render a partial view (a partial view in MVC is essentially an .ascx control). The Render method on System.Web.Mvc.WebFormView might be a good starting place.

Damian Powell
A: 

You're probably going about it the wrong way, to be honest. You should probably have your logic embedded in a library, and then have the user control interface with that library. Then, you could use that same logic to populate values on a form, or similar.

You're probably going to run into a lot of trouble trying to get the control to load, and deal with things that don't exist outside of ASP.Net, like session variables, and viewstate.

Generally, what you're asking for is a report, which is handled by something like Crystal Reports, or SQL Server Reporting Services.

alc6379