开发者

How can I load .ascx user control from console application or windows service?

开发者 https://www.devze.com 2022-12-27 15:16 出处:网络
We use a开发者_如何学Goscx 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.

We use a开发者_如何学Goscx 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消