自闭的Html通用控制? [英] Self closing Html Generic Control?
问题描述
我写了一下code的一个链接标签在code添加到head标签后面......即。
I am writing a bit of code to add a link tag to the head tag in the code behind... i.e.
HtmlGenericControl css = new HtmlGenericControl("link");
css.Attributes["rel"] = "Stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["href"] = String.Format("/Assets/CSS/{0}", cssFile);
要尝试并实现类似...
to try and achieve something like...
<link rel="Stylesheet" type="text/css" href="/CSS/Blah.css" />
我使用HtmlGenericControl实现这个...我遇到的问题是控制ultimatly被呈现为...
I am using the HtmlGenericControl to achieve this... the issue I am having is that the control ultimatly gets rendered as...
<link rel="Stylesheet" type="text/css" href="/CSS/Blah.css"></link>
我似乎无法找到什么,我缺少不会使其他&LT; /联系方式&gt;
,我认为它应该是对象上的属性。
I cant seem to find what I am missing to not render the additional </link>
, I assumed it should be a property on the object.
我缺少的东西,或者这只是不能使用这种控制?
Am I missing something or is this just not possible with this control?
感谢
推荐答案
我觉得你必须从 HtmlGenericControl
导出,并重写渲染
方法。
I think you'd have to derive from HtmlGenericControl
, and override the Render
method.
您会再能写出来的/>你自己(或者你可以使用的HtmlTextWriter的 SelfClosingTagEnd
不变)。
You'll then be able to write out the "/>" yourself (or you can use HtmlTextWriter's SelfClosingTagEnd
constant).
编辑:下面是一个例子(在VB中)
这篇关于自闭的Html通用控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!