Reputation: 32888
Is there a way of using ASP.NET user-controls (.ascx files) to fill my own templating needs within a .NET application, without that application being a Website?
It's actually a class library that will take data in, combine it with a template, then spit it out.
I don't want to write my own templating system from scratch, so I'm looking to re-use ASP.NET functionality for my needs.
I was told that ASP.NET usercontrol rendering is reliant on IIS. Is there some hack or trick to make it work in a .NET class library?
Upvotes: 0
Views: 392
Reputation: 104070
In addition to Rajsh's answer I'd like to point out that there is a web deployment project template for Visual Studio, which allows you to precompile .ascx files into a single assembly.
It simplifies your deployment/installation process. You don't have to copy/synchronize new ascx files, just the created DLL.
Here is a link to the MSDN article.
Upvotes: 0
Reputation: 511
I'm not totally sure if I'm following the question properly, but if you are just looking for a templating engine you might want to check out NVelocity, which is part of the Castle Project.
It allows you to create a template like this (ripped from their getting started guide on the site):
From: $from
To: $to
Subject: $subject
Hello $customer.Name
We're please to yada yada yada.
And then propulate it like so:
Template template = velocity.GetTemplate(@"path/to/myfirsttemplate.vm");
VelocityContext context = new VelocityContext();
context.Put("from", "somewhere");
context.Put("to", "someone");
context.Put("subject", "Welcome to NVelocity");
context.Put("customer", new Customer("John Doe") );
StringWriter writer = new StringWriter();
template.Merge(context, writer);
Console.WriteLine(writer.GetStringBuilder().ToString());
Upvotes: 1
Reputation: 8128
This may be useful to you...may not be exactly what you are looking for..
Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005
Also have a look at
Turning an .ascx User Control into a Redistributable Custom Control
Upvotes: 2