Hi Sean,
No, it is not possible because the Style tag is not a server control that
can runat=â€serverâ€. The Head can runat=â€server’ though. Technically you can
try something like this in the page markup:
<HEAD id="PageHeadSection" runat="server">
</HEAD>
Then in the codebehind:
Protected PageHeadSection As HtmlGenericControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim StyleTag As New HtmlGenericControl
styletag.InnerHtml = "<style>.Container{Background-color:" +
strBackgroundColor + "}</style>"
PageHeadSection.Controls.Add(styletag)
End Sub
Though this is technically possible, I prefer (in terms of separating the
styling from the code) to add the style names dynamically to the server
controls but keep the style definitions static. For example you can create
all the possible styles for the container:
..ContainerRed{/* definitinon*/}
..ContainerBlue{/* definitinon*/}
Then in the codebehind assign the appropriate container style to the objects
cssClass property.