Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've come up with a simpler solution along the lines of Ruben's advice. It has worked without problems for about a month:</p> <pre><code>//Example usage //reference the control var emailCTL = new HtmlCtl.ControlOnDisk&lt;MyControlType&gt;(@"~\Views\EmailTemplates\MyControlType.ascx"); //if you have a code behind you will get intellisense allowing you to set these properties // and re-factoring support works most places except the template file. emailCTL.c.title = "Hello World "; //title is a property in the code behind emailCTL.c.data = data; //data is a property in the code behind string emailBody = emailCTL.RenderStateless(); //Helper Class public class ControlOnDisk&lt;ControlType&gt; where ControlType : UserControl { public ControlType c; Page pageHolder = new Page(); public ControlOnDisk(string path) { var o = pageHolder.LoadControl(path); c = (ControlType)o; pageHolder.Controls.Add(c); } public string RenderStateless() { StringWriter output = new StringWriter(); // set up dumby context for use in rendering to email stream StringBuilder emailMessage = new StringBuilder(); TextWriter tw = new StringWriter(emailMessage); HttpResponse dumbyResponse = new HttpResponse(tw); HttpRequest dumbyRequest = new HttpRequest("", "http://InsertURL.com/", ""); //dummy url requierd for context but not used HttpContext dumbyContext = new HttpContext(dumbyRequest, dumbyResponse); //HttpContextBase dumbyContextBase = new HttpContextWrapper2(dumbyContext); dumbyContext.Server.Execute(pageHolder, output, false); return output.ToString(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload