[英]Render WebPart in a UserControl without containing DIV
I am building a usercontrol to place webparts in my pagelayouts. 我正在建立一个用户控件以将Webpart放置在我的页面布局中。
What i'm basicly doing: 我基本上在做什么:
<uc:WebPartInclude WPName="WebPartName" runat="server"</uc:WebPartInclude>
And this all works fine, except for one thing: It now surrounds the content of the webpart with <div> ... </div>
. 除了一件事情,这一切都工作正常:现在,它用
<div> ... </div>
包围了Webpart的内容。
Since i'm a sucker for clean code, this div
has got to go ^_^ 由于我很喜欢干净的代码,因此该
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;
}
}
}
So the webpart renders the following: 因此,Webpart呈现以下内容:
<div>
... webpart contents
</div>
And i want the surrounding divs to go, got any idea? 我想让周围的divs走,有什么主意吗?
Well, since there was no way of fixing it in a nice way, i just used the HtmlTextWriter
to write the contents to a string and strip the surrounding <div>
... </div>
. 好吧,由于没有办法以一种很好的方式修复它,因此我只是使用
HtmlTextWriter
将内容写入字符串,然后剥离周围的<div>
... </div>
。
Problem solved, just not in a nice way. 问题解决了,只是不是很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.