Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Steve Richter #1
using CSS style and class in server control
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
Steve Richter Guest
-
Composite Control default style attribute
I have a composite control that after dragging it onto the webform adds the following style attribute to the control: style="Z-INDEX: 101; LEFT:... -
Custom Control Class within a class
I think that this problem might relate to another that I posted. I did a page trace of my custom control and see that OnInit is called every time... -
Implementing Control Designer Class for Composite Server Control
I created a custom composite server control with 2 literals and 1 text box. The control displays fine in internet explorer, but doesnt display... -
XP Style Manifest in a Class Library
I know how to use the manifest to acheive XP style controls in an executable file, but how can this be aceived in a class library? I have a... -
xp style control - Drop Down
Hi I dont know if such a control exists but its not hard doing it simply use a div with display=none and toggle it, In Explorer you can add... -
lisa@starways.net #2
Re: using CSS style and class in server control
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
Steve Richter wrote:in> 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> each <a> element of my menu control?
>
> thanks,
>
> -Stevelisa@starways.net Guest



Reply With Quote

