c# - 将 html 添加到 CreateChildControls() 方法

标签 c# moss sharepoint-2007 web-parts

我在 CreateChildControls() 方法的 Web 部件中使用 MOSS 2007,我的代码如下:

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

我的问题是如何插入 html,以便我可以在这些控件周围包裹一个 div,无需使用 RenderWebPart() 方法。

我正在尝试实现此目标,因为我不想使用 id 将是自动生成的客户端 id 的面板。

非常感谢,

最佳答案

我不确定是否有某种原因这不适用于 Web 部件,但这似乎可以解决 Web 用户控件的问题:

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

}

关于c# - 将 html 添加到 CreateChildControls() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2129255/

相关文章:

c# - 如何使用 ASP.NET Core 2.0 和 newtonsoft.json

c# - 对于在 ASP.NET Web 角色中执行的套接字读取循环来说,缓冲区大小越大越好吗?

powershell - 我可以从脚本或命令行将文件复制到网上邻居吗?

c# - IoC 和 .NET 框架

c# - 是否应为同一实体创建多个数据契约(Contract)

开发人员生产中的 SharePoint 权限级别

sharepoint - Web 部件未显示在“添加 Web 部件”对话框中

c# - 将 ValidationGroup 与 Sharepoint EditorPart 结合使用

web-services - 共享点 2007 : How to change a custom webpart webservice URL?

sharepoint-2007 - 如何将文件添加到 SharePoint 2007 中网站定义中的文档库?