开发者

How do I add CSS styles to an ASP.NET UserControl from the code-behind?

this.Style.Add ( /*...*/ )

...开发者_JAVA百科 doesn't appear to work.

What do I need to do to add a style to it?


Think about the nature of UserControl - it's intended to contain other ASP.NET controls and that's why you cannot set CSS for whole control.. instead you just need to specify styles for each child control individually. You can also take a look at the ApplyStyleSheetSkin method.


You may wrap your user control into another html container (div for example) and set style on container.


If your user control is inheriting from webcontrol simply use the system.web.ui.webcontrols.webcontrol.cssclass (msdn). Example in the link.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜