![](/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.