Here's another way... For example:
Parent ASPX portion:
<div id="div1" class="xyz" style="width: 40px; height: 40px;">
<span>abc</span>
</div>
Within 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, then you will need to merge the style with the control using the MergeStyle method. (This requires that the control be runat="server"
).
This code renders the following output: (Showing 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>