一些測試,它看起來像的原因之後是HtmlGenericControl
不支持自動關閉。在服務器端HtmlGenericControl("br")
被視爲:
<br runat="server"></br>
有HTML中沒有</br>
標籤,所以瀏覽器顯示它有兩種<br />
標籤。尼斯出路是創建HtmlGenericSelfCloseControl
像這樣(對不起,C#代碼,但你應該沒有問題,在VB.NET rewritting此):
public class HtmlGenericSelfCloseControl : HtmlGenericControl
{
public HtmlGenericSelfCloseControl()
: base()
{
}
public HtmlGenericSelfCloseControl(string tag)
: base(tag)
{
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write(HtmlTextWriter.TagLeftChar + this.TagName);
Attributes.Render(writer);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}
public override ControlCollection Controls
{
get { throw new Exception("Self closing tag can't have child controls"); }
}
public override string InnerHtml
{
get { return String.Empty; }
set { throw new Exception("Self closing tag can't have inner content"); }
}
public override string InnerText
{
get { return String.Empty; }
set { throw new Exception("Self closing tag can't have inner text"); }
}
}
而且用它來代替:
pDoc.Controls.Add(New Label With {.Text = "whatever"})
pDoc.Controls.Add(New HtmlGenericSelfCloseControl("br"))
作爲一個簡單的替代方法(如果你有參考Page
),你可以嘗試使用Page.ParseControl
:
pDoc.Controls.Add(New Label With {.Text = "whatever"})
pDoc.Controls.Add(Page.ParseControl("br"))
你確定它是呈現'
''不
'? – tpeczek
是的,他是正確的渲染
–