![](/img/trans.png)
[英]How to render a WPF UserControl to a bitmap without creating a window
[英]Render WebPart in a UserControl without containing DIV
我正在建立一个用户控件以将Webpart放置在我的页面布局中。
我基本上在做什么:
<uc:WebPartInclude WPName="WebPartName" runat="server"</uc:WebPartInclude>
除了一件事情,这一切都工作正常:现在,它用<div> ... </div>
包围了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>
我想让周围的divs走,有什么主意吗?
好吧,由于没有办法以一种很好的方式修复它,因此我只是使用HtmlTextWriter
将内容写入字符串,然后剥离周围的<div>
... </div>
。
问题解决了,只是不是很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.