IDesignerHost.CreateComponent

Discussion in 'ASP .Net Web Controls' started by Peter Young, Sep 1, 2004.

  1. Peter Young

    Peter Young Guest

    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
    Peter Young, Sep 1, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?cm9iZXJ0bw==?=
    Replies:
    0
    Views:
    555
    =?Utf-8?B?cm9iZXJ0bw==?=
    Oct 25, 2004
Loading...

Share This Page