Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET自定义web控件样式呈现样式规则_Asp.net_Css_Inheritance_Custom Controls - Fatal编程技术网

ASP.NET自定义web控件样式呈现样式规则

ASP.NET自定义web控件样式呈现样式规则,asp.net,css,inheritance,custom-controls,Asp.net,Css,Inheritance,Custom Controls,我有一个从ASP.NET按钮控件继承的自定义web控件。在Render method override中,我将呈现自己的HTML输出(div)。问题是如何以最正确的方式呈现该控件的样式属性 我可以简单地迭代for/foreach循环中的样式集合并将其写入HTMLTextWriter,但是可能.NET有一个内置方法将样式定义写入htmlwriter 谢谢听起来您想要的是ApplyStyle()方法: var style = new Style(); style.ForeColor = System

我有一个从ASP.NET按钮控件继承的自定义web控件。在Render method override中,我将呈现自己的HTML输出(div)。问题是如何以最正确的方式呈现该控件的样式属性

我可以简单地迭代for/foreach循环中的样式集合并将其写入HTMLTextWriter,但是可能.NET有一个内置方法将样式定义写入htmlwriter


谢谢

听起来您想要的是
ApplyStyle()
方法:

var style = new Style();
style.ForeColor = System.Drawing.Color.Red;
style.BackColor = System.Drawing.Color.Yellow;

var ctrl = new WebControl();
ctrl.ApplyStyle(style);

解决方案是在ASP.NET WebControl中使用CSSStylection对象的Value属性。

不完全是……我已经有了一个样式集合作为WebControl的属性。但我发现解决方案-CssStyleCollection有一个Value属性,它返回的正是我需要的:)