Dynamically Adding UserControls Page.Parse

J

Jim Davis

I'm dynamically adding controls to a page using xsl and its working great
when using asp server controls. If I try to dynamically add a user control,
I get the error "Unknown server tag 'cal:Calendar'."
My user control renders fine if I drag and drop it on the page. Is it
possible to register a UserControl so the Page.Parse method recognizes it?

The code I'm using is:


XPathDocument doc = new XPathDocument(Server.MapPath("RptConfig.xml"));
XslTransform t = new XslTransform();
t.Load(Server.MapPath("RptConfig.xslt"));

//Transform the config XML to a String Writer.
StringWriter sw = new StringWriter();t.Transform(doc, null, sw, null);

//Extract the resulting Control XML, and remove the asp: namespace
declaration
string result = sw.ToString();
result = result.Replace("xmlns:asp=\"remove\"", "");


//Parse the controls
Control ctl = Page.ParseControl(result);
//Now add the controls to the placeholder.
phDynamic.Controls.Add(ctl);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top