【问题标题】:Render WebPart in a UserControl without containing DIV在不包含 DIV 的用户控件中呈现 WebPart
【发布时间】:2014-09-09 19:29:21
【问题描述】:

我正在构建一个用户控件以将 web 部件放置在我的页面布局中。

我基本上在做什么:

<uc:WebPartInclude WPName="WebPartName" runat="server"</uc:WebPartInclude>

这一切都很好,除了一件事:它现在用&lt;div&gt; ... &lt;/div&gt;包围webpart的内容。

因为我是干净代码的傻瓜,这个div 必须离开^_^

public class WebPartInclude : Control
{
    public string WPName = "";
    private WebControl webPartControl = null;
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        webPartControl = (WebControl)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("full path..." + WPName);
    }

    protected override void Render(HtmlTextWriter writer)
    {
        base.RenderChildren (writer);
    }
    protected override void CreateChildControls()
    {
        if (webPartControl != null)
            Controls.Add(webPartControl);
        ChildControlsCreated = true;
    }

    public override ControlCollection Controls
    {
        get
        {
            EnsureChildControls();
            return base.Controls;
        }
    }
}

因此 webpart 呈现以下内容:

<div>
    ... webpart contents
</div>

我想要周围的 div 去,知道吗?

【问题讨论】:

    标签: c# .net sharepoint user-controls web-parts


    【解决方案1】:

    好吧,因为没有办法很好地修复它,我只是使用HtmlTextWriter 将内容写入字符串并剥离周围的&lt;div&gt;...&lt;/div&gt;

    问题解决了,只是方法不好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-20
      • 1970-01-01
      • 2019-03-20
      相关资源
      最近更新 更多