Hi Steve,
It's a matter of taste, I think. You can include the stylesheet in
your control and mark it Embedded Resource. Then you can use
RegisterClientScriptBlock to add it to the page (it doesn't matter that
it's a stylesheet and not a script block). If you use
IsClientScriptBlockRegistered, you can ensure that you only get one
copy of the script added in. Here's an example of reading the resource
into the page. I call this in PreRender:
Protected Overridable Sub RegisterScript()
'this script is client script and should appear only once
If Not Page.IsClientScriptBlockRegistered("ListBoxPlus_js") Then
Dim reader As New StreamReader(Me.GetType().Assembly.
GetManifestResourceStream(Me.GetType(), "ListBoxPlus.js"))
Dim script As String = "<script language='javascript'
type='text/javascript' >" _
+ ControlChars.CrLf _
+ "<!--" _
+ ControlChars.CrLf _
+ reader.ReadToEnd() _
+ ControlChars.CrLf _
+ "//-->" _
+ ControlChars.CrLf _
+ "</script>"
Page.RegisterClientScriptBlock("ListBoxPlus_js", script)
reader = Nothing
script = Nothing
End If
In terms of ensuring that you don't walk on other styles that the user
might use, one solution is to use unfriendly names like
MyBigDamnControl_TableHeader. Things that aren't likely to be
duplicated. Or you can just put the styles into the Render, which is a
bit of a pain, but you only have to do it once (twice, if you use a
custom designer), and then it's done and more or less bulletproof.
Lisa
[quoted text, click to view] Steve Richter wrote:
> Looking for some basic guidance on how or whether I should use class=
> and <style> and whatever you call CSS to control the appearance of my
> menu server control.
>
> It is great that I can render a sequence of <a> elements to the page,
> using the class= attribute to control the appearance, with the result
> being a decent looking menu bar.
>
> But how do I inject the CSS classes into the style block of the page?
> And once those classes are placed in the page, how does the server
> control avoid name clashes with other server controls doing the same
> thing?
>
> What is the alternative? Do I have to duplicate the style behavior
in
> each <a> element of my menu control?
>
> thanks,
>
> -Steve