本文介绍了发送<风格>从自定义服务器的ASP元素信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要发送到输出的信息CSS风格块
I want send to output CSS info in style blocks
protected override void RenderContents(HtmlTextWriter output)
{
...
output.Write("<style> .... ");
}
不过,此块不能嵌套在DIV块。我必须把它放在head.How我能做到这一点还是有另一种方法?
But this block cant be nested in div block .I must place it in head.How can I do it or is there another approach?
推荐答案
的方法让你添加样式的&LT; HEAD&GT;
。然而,CSS属性,你可以指定仅限于那些由的类。 (你可以从的风格中派生自己的类
如果你需要额外的属性)。
The this.Page.Header.Stylesheet.CreateStyleRule
method lets you add styles to the <head>
. However, the CSS attributes that you can specify are limited to those supported by the Style
class. (You can derive your own class from Style
if you need additional attributes.)
C#示例:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
// Create a Style object for the body of the page.
Style bodyStyle = new Style();
bodyStyle.ForeColor = System.Drawing.Color.Blue;
bodyStyle.BackColor = System.Drawing.Color.LightGray;
// Add the style rule named bodyStyle to the header
// of the current page. The rule is for the body HTML element.
this.Page.Header.StyleSheet.CreateStyleRule(bodyStyle, null, "body");
}
这篇关于发送&LT;风格&GT;从自定义服务器的ASP元素信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!