Dynamically generating CSS classes

Discussion in 'ASP .Net Building Controls' started by Nathan Sokalski, Dec 23, 2007.

  1. There are many situations in which we want to assign certain styles with
    multiple CSS properties to a control, quite often the same ones for multiple
    controls. Sometimes these styles must be dynamically generated just like the
    other parts of the control. Because of the need to have the style
    dynamically generated, a static CSS class is not appropriate. I would like
    to know if anybody knows of a good way to add a CSS class from within a
    custom control. I would like to do this so that I can simply assign the CSS
    class to the control. My reason for wanting to do this is so that rather
    than have a bunch of controls with style attributes that are huge, they just
    have a simple class attribute. This would significantly decrease the
    download size for controls that use the same style multiple times. If
    anybody knows of a good way to do this, please let me know. Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Dec 23, 2007
    #1
    1. Advertising

  2. On Dec 23, 4:56 am, "Nathan Sokalski" <> wrote:
    > There are many situations in which we want to assign certain styles with
    > multiple CSS properties to a control, quite often the same ones for multiple
    > controls. Sometimes these styles must be dynamically generated just like the
    > other parts of the control. Because of the need to have the style
    > dynamically generated, a static CSS class is not appropriate. I would like
    > to know if anybody knows of a good way to add a CSS class from within a
    > custom control. I would like to do this so that I can simply assign the CSS
    > class to the control. My reason for wanting to do this is so that rather
    > than have a bunch of controls with style attributes that are huge, they just
    > have a simple class attribute. This would significantly decrease the
    > download size for controls that use the same style multiple times. If
    > anybody knows of a good way to do this, please let me know. Thanks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/


    There is a Style Class that represents the style of a web server
    control
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.style.aspx

    Example: Button1.Style.Add("width", "100px");
     
    Alexey Smirnov, Dec 23, 2007
    #2
    1. Advertising

  3. That does not create a CSS class, it simply adds CSS properties to the
    control's style attribute. I am looking to create a CSS class that could be
    used the same way as the following:

    <style type="text/css">
    .myclass{width:100px;}
    </style>

    Any classes that would be generated would have more CSS properties than
    this, but the point is to be able to use the class attribute rather than the
    style attribute.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Alexey Smirnov" <> wrote in message
    news:...
    On Dec 23, 4:56 am, "Nathan Sokalski" <> wrote:
    > There are many situations in which we want to assign certain styles with
    > multiple CSS properties to a control, quite often the same ones for
    > multiple
    > controls. Sometimes these styles must be dynamically generated just like
    > the
    > other parts of the control. Because of the need to have the style
    > dynamically generated, a static CSS class is not appropriate. I would like
    > to know if anybody knows of a good way to add a CSS class from within a
    > custom control. I would like to do this so that I can simply assign the
    > CSS
    > class to the control. My reason for wanting to do this is so that rather
    > than have a bunch of controls with style attributes that are huge, they
    > just
    > have a simple class attribute. This would significantly decrease the
    > download size for controls that use the same style multiple times. If
    > anybody knows of a good way to do this, please let me know. Thanks.
    > --
    > Nathan Sokalski
    > ://www.nathansokalski.com/


    There is a Style Class that represents the style of a web server
    control
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.style.aspx

    Example: Button1.Style.Add("width", "100px");
     
    Nathan Sokalski, Dec 23, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Poppy
    Replies:
    1
    Views:
    360
    Hans Kesting
    Jul 30, 2004
  2. Carfield Yim
    Replies:
    1
    Views:
    1,486
    Andrew Thompson
    May 31, 2004
  3. Nathan Sokalski

    Dynamically generating CSS classes

    Nathan Sokalski, Dec 23, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    420
    Nathan Sokalski
    Dec 23, 2007
  4. Jonas Galvez

    Dynamically generating classes?

    Jonas Galvez, Sep 27, 2005, in forum: Ruby
    Replies:
    14
    Views:
    261
    Austin Ziegler
    Sep 28, 2005
  5. Mark Smith

    CSS classes within classes

    Mark Smith, Dec 22, 2008, in forum: Javascript
    Replies:
    3
    Views:
    132
    Mark Smith
    Dec 22, 2008
Loading...

Share This Page