Programmatically adding a css style to a web content form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan Sokalski

    Programmatically adding a css style to a web content form

    I have css that would normally be placed in style tags in the header of the
    Master page that I want to add programmaticall y for a specific Web Content
    Form (the *.aspx page). How do I do this for a Web Content Form? I cannot
    use style tags in a Web Content Form, and I am having trouble figuring out
    how to add all the desired css properties to a
    System.Web.UI.W ebControls.Styl e object. Can anyone help me? Thanks.
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。



  • Peter Bucher [MVP]

    #2
    Re: Programmaticall y adding a css style to a web content form

    Hello Nathan
    >I have css that would normally be placed in style tags in the header of the
    >Master page that I want to add programmaticall y for a specific Web Content
    >Form (the *.aspx page). How do I do this for a Web Content Form? I cannot
    >use style tags in a Web Content Form, and I am having trouble figuring out
    >how to add all the desired css properties to a
    >System.Web.UI. WebControls.Sty le object. Can anyone help me? Thanks.
    You can Access within your contentpage to the masterpage and throught the
    property ".Master"
    also to the .Header.

    Add there a HtmlGenericCont rol("style"), or make an Include with an "link"
    Tag there.

    Look further:

    -

    (English Translation)

    -

    (Original)

    --
    Gruss, Peter Bucher
    Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

    Comment

    • Stan

      #3
      Re: Programmaticall y adding a css style to a web content form

      ... and I am having trouble figuring out
      how to add all the desired css properties to a
      System.Web.UI.W ebControls.Styl e object. Can anyone help me? Thanks.

      The "Style" property of a web server control is actually a collection
      not a single object (really ought to be named "Styles"). So you use
      the Add method. CssStyleCollect ions are actually a list of key/value
      pairs where the key is the attribute and the value the value. For
      example:

      Suppose you have a label control where you want to set the styles
      programmaticall y:

      Label1.Style.Ad d("Color", "Blue");
      Label1.Style.Ad d("font-size", "2em");

      will make the text quite large and blue.

      HTH

      Comment

      • Nathan Sokalski

        #4
        Re: Programmaticall y adding a css style to a web content form

        I am not talking about the Style property of a web server control, I am
        talking about a Web.UI.WebContr ols.Style object, which does not have an Add
        method. You seem to have the Style object confused with the
        CssStyleCollect ion object. These two object can be easy to confuse because
        the Style property is not an instance of the Style class. Any other
        suggestions?
        --
        Nathan Sokalski
        njsokalski@hotm ail.com
        有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


        "Stan" <google@philpha ll.me.ukwrote in message
        news:fd22485c-66da-48a6-bcff-cd555c7fc8bb@b1 g2000hsg.google groups.com...
        >... and I am having trouble figuring out
        >how to add all the desired css properties to a
        >System.Web.UI. WebControls.Sty le object. Can anyone help me? Thanks.
        >
        >
        The "Style" property of a web server control is actually a collection
        not a single object (really ought to be named "Styles"). So you use
        the Add method. CssStyleCollect ions are actually a list of key/value
        pairs where the key is the attribute and the value the value. For
        example:
        >
        Suppose you have a label control where you want to set the styles
        programmaticall y:
        >
        Label1.Style.Ad d("Color", "Blue");
        Label1.Style.Ad d("font-size", "2em");
        >
        will make the text quite large and blue.
        >
        HTH
        >

        Comment

        • Stan

          #5
          Re: Programmaticall y adding a css style to a web content form

          On May 9, 1:06 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
          I am not talking about the Style property of a web server control, I am
          talking about a Web.UI.WebContr ols.Style object, which does not have an Add
          method. You seem to have the Style object confused with the
          CssStyleCollect ion object. These two object can be easy to confuse because
          the Style property is not an instance of the Style class. Any other
          suggestions?
          --
          Nathan Sokalski
          njsokal...@hotm ail.comhttp://www.nathansokal ski.com/
          >
          "Stan" <goo...@philpha ll.me.ukwrote in message
          >
          news:fd22485c-66da-48a6-bcff-cd555c7fc8bb@b1 g2000hsg.google groups.com...
          >
          >
          >
          ...  and I am having trouble figuring out
          how to add all the desired css properties to a
          System.Web.UI.W ebControls.Styl e object. Can anyone help me? Thanks.
          >
          The "Style" property of a web server control is actually a collection
          not a single object (really ought to be named "Styles"). So you use
          the Add method. CssStyleCollect ions are actually a list of key/value
          pairs where the key is the attribute and the value the value. For
          example:
          >
          Suppose you have a label control where you want to set the styles
          programmaticall y:
          >
                 Label1.Style.Ad d("Color", "Blue");
                 Label1.Style.Ad d("font-size", "2em");
          >
          will make the text quite large and blue.
          >
          HTH- Hide quoted text -
          >
          - Show quoted text -
          Ok, I misread your post slightly. Can I take it then that you are
          trying encapsulate a set of css styles in an instance of
          System.Web.UI.W ebControl.Style class so it can be applied to any
          control without having to set the properties for each control
          individually? i.e. you are trying to emulate the way css "class"
          attributes work without having to access the <styletags.

          I have tested the following which works OK
          (note that System.Web.UI.W ebControl namespace is within scope)

          Style s = new Style();
          s.Font.Size = FontUnit.Parse( "2em");
          s.ForeColor = System.Drawing. Color.Blue;
          Label1.ControlS tyle.CopyFrom(s );

          Is that anything like what you are trying to do?

          Note also that the Style object does not encapsulate all possible css
          styles, e.g. it doesn't handle things like "margin" or "padding"
          However the Style object does have a CssClass property that can be
          used in the same way as those illustrated above except that the
          definition of the css class has to reside in markup in the usual way.

          Is there any reason why you can't use themes for all this, which allow
          the selected application of both Skin and CSS style sheets, and can be
          applied at page level using the @page directive (including content
          pages) and hence at control level with css classes and Skin IDs?





          Comment

          • Nathan Sokalski

            #6
            Re: Programmaticall y adding a css style to a web content form

            Thank you for that information. I think the basic scenario of my situation
            is that I am using Master/Content pages, and the CSS class I want will only
            be used in one content page. However, the CSS class will not always be the
            same, so it must be generated, so I cannot place it in the HTML or an
            external stylesheet like you normally would.
            --
            Nathan Sokalski
            njsokalski@hotm ail.com
            有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


            "Stan" <googlestan@phi lhall.netwrote in message
            news:b2595620-785f-4bae-a778-03ac56ae30dc@i7 6g2000hsf.googl egroups.com...
            On May 9, 1:06 am, "Nathan Sokalski" <njsokal...@hot mail.comwrote:
            I am not talking about the Style property of a web server control, I am
            talking about a Web.UI.WebContr ols.Style object, which does not have an
            Add
            method. You seem to have the Style object confused with the
            CssStyleCollect ion object. These two object can be easy to confuse because
            the Style property is not an instance of the Style class. Any other
            suggestions?
            --
            Nathan Sokalski
            njsokal...@hotm ail.comhttp://www.nathansokal ski.com/
            >
            "Stan" <goo...@philpha ll.me.ukwrote in message
            >
            news:fd22485c-66da-48a6-bcff-cd555c7fc8bb@b1 g2000hsg.google groups.com...
            >
            >
            >
            ... and I am having trouble figuring out
            how to add all the desired css properties to a
            System.Web.UI.W ebControls.Styl e object. Can anyone help me? Thanks.
            >
            The "Style" property of a web server control is actually a collection
            not a single object (really ought to be named "Styles"). So you use
            the Add method. CssStyleCollect ions are actually a list of key/value
            pairs where the key is the attribute and the value the value. For
            example:
            >
            Suppose you have a label control where you want to set the styles
            programmaticall y:
            >
            Label1.Style.Ad d("Color", "Blue");
            Label1.Style.Ad d("font-size", "2em");
            >
            will make the text quite large and blue.
            >
            HTH- Hide quoted text -
            >
            - Show quoted text -
            Ok, I misread your post slightly. Can I take it then that you are
            trying encapsulate a set of css styles in an instance of
            System.Web.UI.W ebControl.Style class so it can be applied to any
            control without having to set the properties for each control
            individually? i.e. you are trying to emulate the way css "class"
            attributes work without having to access the <styletags.

            I have tested the following which works OK
            (note that System.Web.UI.W ebControl namespace is within scope)

            Style s = new Style();
            s.Font.Size = FontUnit.Parse( "2em");
            s.ForeColor = System.Drawing. Color.Blue;
            Label1.ControlS tyle.CopyFrom(s );

            Is that anything like what you are trying to do?

            Note also that the Style object does not encapsulate all possible css
            styles, e.g. it doesn't handle things like "margin" or "padding"
            However the Style object does have a CssClass property that can be
            used in the same way as those illustrated above except that the
            definition of the css class has to reside in markup in the usual way.

            Is there any reason why you can't use themes for all this, which allow
            the selected application of both Skin and CSS style sheets, and can be
            applied at page level using the @page directive (including content
            pages) and hence at control level with css classes and Skin IDs?






            Comment

            Working...