将 html 添加到 CreateChildControls() 方法

发布于 2024-08-19 05:14:30 字数 808 浏览 2 评论 0原文

我在 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,没有< /strong> 使用 RenderWebPart() 方法。

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

非常感谢,

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,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

肤浅与狂妄 2024-08-26 05:14:30

我不确定是否有某种原因这不适用于 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);

}

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

}
秋风の叶未落 2024-08-26 05:14:30

Panel 呈现为

。试试这个:

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

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);
}
过期以后 2024-08-26 05:14:30

我正在处理类似的事情,我想将新的 SP 2013“+ 添加新公告”放入我的自定义 Web 部件中。

我尝试了这个,并且有效,但我不知道这是否是一个好方法。基本上你可以把任何html放在我发现的litteralcontrol中...

string contents = "<div class=\"ms-comm-heroLinkContainer wp-custom-addnew\"><a id=\"forum0-NewPostLink\" class=\"ms-textXLarge ms-heroCommandLink\" title=\"add new announcement\" href=\"" + list.DefaultNewFormUrl + "\"><span class=\"ms-list-addnew-imgSpan20\"><img class=\"ms-list-addnew-img20\" src=\"/_layouts/15/images/company/SPSPrite.png\"></span><span>New Announcement</span></a><div class=\"ms-clear\"></div></div>";

LiteralControl link = new LiteralControl(contents);

this.Controls.Add(link);

请告诉我是否有更好的方法来发布“原始自定义”html。

I'm working with something similar, and I wanted to put the new SP 2013 " + add new announcement" in my custom webpart.

I tried this, and it worked, but I dont know if it's a good way to do it. Basically you can put whatever html in a litteralcontrol I found out...

string contents = "<div class=\"ms-comm-heroLinkContainer wp-custom-addnew\"><a id=\"forum0-NewPostLink\" class=\"ms-textXLarge ms-heroCommandLink\" title=\"add new announcement\" href=\"" + list.DefaultNewFormUrl + "\"><span class=\"ms-list-addnew-imgSpan20\"><img class=\"ms-list-addnew-img20\" src=\"/_layouts/15/images/company/SPSPrite.png\"></span><span>New Announcement</span></a><div class=\"ms-clear\"></div></div>";

LiteralControl link = new LiteralControl(contents);

this.Controls.Add(link);

Please tell me if there is a better way of posting "raw custom" html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文