I would like to create dynamic content pages in a HttpHandlerFactory while leaving the master pages completely to be defined in web designer (xyz.master / xyz.master.cs / xyz.master.designer.cs). Dynamic means that i want to create the content pages completely in code rather than filling some content into pre-defined (design mode) content pages. The problem is the use of the content object. It's not possible to set the ContentPlaceholderId at runtime. My ideo was to do something like that:
public IHttpHandler GetHandler(HttpContext context, string requestType, String url, String pathTranslated)
{
// === Create the content page and set the master ===
Page handler = new Page();
handler.MasterPageFile = "Default.Master";
// === Create the content container for placeholder 'ContentPlaceHolder1'
Content content1 = new Content();
content1.ContentPlaceHolderID = "ContentPlaceHolder1";
// === Create any control to be placed in ContentPlaceHolder1 finally ===
Button b1 = new Button();
b1.Text = "I'm a button";
// === Do the plumbing ===
content1.Controls.Add(b1);
handler.Controls.Add(content1);
return (IHttpHandler)handler;
}
Any Ideas how to get this running?
Best Regards,
Joachim