IDesignerHost.CreateComponent

P

Peter Young

I would like to add a control to the aspx page that my control is sited on, programmatically at design time.

I understand that IDesignerHost.CreateComponent is the method to use, and it appears to add the control to some extent,
but the control never appears on the design surface, and also does not persist.

Here's the test code:

IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
TextBox textBox1 = host.CreateComponent(typeof(TextBox)) as TextBox;
textBox1.Text = "hello";

The result of running this is the properties window's dropdown shows the textbox, and the Text property is correct. The
code-behind also shows the textbox is declared. But the textbox never shows on the design surface, never shows in the
html, and once you switch to html view, then back to design view, the control is gone.

What am I missing here?

TIA,
Pete
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top