using CSS style and class in server control

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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:...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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:
    > 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
    lisa@starways.net Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139