Search code examples
c#mosssharepoint-2007web-parts

Adding html to CreateChildControls() method


I'm using MOSS 2007 in my webpart within my CreateChildControls() method I have the code below:

     protected override void CreateChildControls()
        {
        base.CreateChildControls();

        Panel myPanel = new Panel();
        myPanel.ID = "SelectionPanel";
        this.Controls.Add(myPanel);

        this.myGridView = new GridView();
        createMyGridView(ref myGridView);
        myPanel.Controls.Add(myGridView);

        this._btnUpdate = new Button();
        this._btnUpdate.Text = "Update";
        myPanel.Controls.Add(_btnUpdate);
        this._btnUpdate.Click += new EventHandler(_btnUpdate_Click);
}

My question is how do insert html so I can wrap a div around these controls, without using the RenderWebPart() method.

I am trying to acheive this because i dont want to use a panel whose id will be an autogenerated client id.

Many Thanks,


Solution

  • I'm not sure if there's some reason this wouldn't work for a webpart, but this seems to do the trick for a web user control:

    protected override void CreateChildControls()
    {
    base.CreateChildControls();
    
    var container = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
    container.Attributes.Add("id","SelectionPanel");
    
    TextBox tb = new TextBox();
    container.Controls.Add(tb);
    
    this.Controls.Add(container);
    
    }