views:

329

answers:

2

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,

+1  A: 

Panel render as <div>. Try this:

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

    Panel around = new Panel();

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

    // ... other controls ... \\

    this.Controls.Add(around);
}
Rubens Farias
Sorry, I have tried this but this generates an autogenreated client id on the panel which i don't want
test
A: 

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);

}
kristian
\Thanks worked a treat!!
test