简体   繁体   中英

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

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

... 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.

您可以将用户控件包装到另一个html容器(例如div)中,并在容器上设置样式。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM