Here is another way ... For example:
Part of parent ASPX:
<div id="div1" class="xyz" style="width: 40px; height: 40px;"> <span>abc</span> </div>
Inside the control:
Dim xyzStyle As New Style() xyzStyle.CssClass = "xyz" xyzStyle.BackColor = Drawing.Color.LightBlue Page.Header.StyleSheet.CreateStyleRule(xyzStyle, Nothing, ".xyz")
Note that this assumes that the parent ASPX page has the class attribute set for the target control. If not, you will need to combine the style with the control using the MergeStyle method. (This requires the control to be runat="server" ).
This code displays the following result: (Showing the entire source for your convenience)
<html> <head> <title>Untitled Page </title> <style type="text/css"> .xyz { background-color:LightBlue; } </style> </head> <body> <form name="form1" method="post" action="MyPage.aspx" id="form1"> <div id="div1" class="xyz" style="width: 40px; height: 40px;"> <span>abc</span> </div> </form> </body> </html>
Cerebrus
source share