Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. style sheet

style sheet

Scheduled Pinned Locked Moved C#
csharphtmlcsshelpquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zapap
    wrote on last edited by
    #1

    I'd like to get and set the left property in a css in my code behind file. Style sheet: #lblLabel { top:100px; width:100px; } Code behind file (c#) protected override CreateChildControls() { // Add the opening html ... // Add the Label string sLeft = 0; Label lblLabel = new Label(); lblLabel.ID = "lblLabel"; lblLabel.Text = "Hello"; lblLabel.Style["left"] = "100px"; <=========== works fine sLeft = lblLabel.Style["left"]; <=========== doesn't work ??? Form.cantrols.Add(lblLabel); } If anyone can help me, I'd me very grateful. Thx There is someone in my head but it's not me - Pink Floyd

    G Z 2 Replies Last reply
    0
    • Z zapap

      I'd like to get and set the left property in a css in my code behind file. Style sheet: #lblLabel { top:100px; width:100px; } Code behind file (c#) protected override CreateChildControls() { // Add the opening html ... // Add the Label string sLeft = 0; Label lblLabel = new Label(); lblLabel.ID = "lblLabel"; lblLabel.Text = "Hello"; lblLabel.Style["left"] = "100px"; <=========== works fine sLeft = lblLabel.Style["left"]; <=========== doesn't work ??? Form.cantrols.Add(lblLabel); } If anyone can help me, I'd me very grateful. Thx There is someone in my head but it's not me - Pink Floyd

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Standard question #1: What do you mean by "not working"? When I try your code, I get the value "100px" in the string sLeft, just as expected. You put the value in the Style collection and read it on the next line. Why shouldn't that work? --- b { font-weight: normal; }

      Z 1 Reply Last reply
      0
      • Z zapap

        I'd like to get and set the left property in a css in my code behind file. Style sheet: #lblLabel { top:100px; width:100px; } Code behind file (c#) protected override CreateChildControls() { // Add the opening html ... // Add the Label string sLeft = 0; Label lblLabel = new Label(); lblLabel.ID = "lblLabel"; lblLabel.Text = "Hello"; lblLabel.Style["left"] = "100px"; <=========== works fine sLeft = lblLabel.Style["left"]; <=========== doesn't work ??? Form.cantrols.Add(lblLabel); } If anyone can help me, I'd me very grateful. Thx There is someone in my head but it's not me - Pink Floyd

        Z Offline
        Z Offline
        zapap
        wrote on last edited by
        #3

        Hi // I see that my question is not very clear... // I set the left in the css file. #lblLabel { Left:100px; ... } // Now in the code behind. ... Label lblLabel = new Label(); string sLeft = lblLabel.Style["left"]; ... // now why is sLeft != "100px" ?? // Thank you. There is someone in my head but it's not me - Pink Floyd

        1 Reply Last reply
        0
        • G Guffa

          Standard question #1: What do you mean by "not working"? When I try your code, I get the value "100px" in the string sLeft, just as expected. You put the value in the Style collection and read it on the next line. Why shouldn't that work? --- b { font-weight: normal; }

          Z Offline
          Z Offline
          zapap
          wrote on last edited by
          #4

          // Hi // I see that my question is not very clear... // I set the left in the css file. #lblLabel { Left:100px; ... } // Now in the code behind. ... Label lblLabel = new Label(); string sLeft = lblLabel.Style["left"]; ... // now why is sLeft != "100px" ?? // Thank you. There is someone in my head but it's not me - Pink Floyd There is someone in my head but it's not me - Pink Floyd

          G 1 Reply Last reply
          0
          • Z zapap

            // Hi // I see that my question is not very clear... // I set the left in the css file. #lblLabel { Left:100px; ... } // Now in the code behind. ... Label lblLabel = new Label(); string sLeft = lblLabel.Style["left"]; ... // now why is sLeft != "100px" ?? // Thank you. There is someone in my head but it's not me - Pink Floyd There is someone in my head but it's not me - Pink Floyd

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            Because the value for the left style is present in the style sheet, not in the style property of the label. When you set the style on the id of the label, it only inherits the style, it's not copied into the style property of the label. Furthermore, the css file is loaded by the browser, not the server. The server does not even know that there is a style added to the id. --- b { font-weight: normal; }

            Z 1 Reply Last reply
            0
            • G Guffa

              Because the value for the left style is present in the style sheet, not in the style property of the label. When you set the style on the id of the label, it only inherits the style, it's not copied into the style property of the label. Furthermore, the css file is loaded by the browser, not the server. The server does not even know that there is a style added to the id. --- b { font-weight: normal; }

              Z Offline
              Z Offline
              zapap
              wrote on last edited by
              #6

              Oh, I see. I'm very new to ASP.NET (2 months to be precise), so I bought ASP.NET Unleashed. Very good book. But what would be the best way to place controls dynamically at a specific position then? Thanks for the help. I appreciate it very much. There is someone in my head but it's not me - Pink Floyd

              G 1 Reply Last reply
              0
              • Z zapap

                Oh, I see. I'm very new to ASP.NET (2 months to be precise), so I bought ASP.NET Unleashed. Very good book. But what would be the best way to place controls dynamically at a specific position then? Thanks for the help. I appreciate it very much. There is someone in my head but it's not me - Pink Floyd

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Unless you need any specific functionality provided by the Label class, I think that you are better off using the HtmlControls instead of WebControls for this. That way you know exactly how they will be rendered, regardless of the browser. Use a regular div tag with runat="server", this will become a HtmlGenericControl in the server code. You need to specify css for position:absolute and set left and top to position the element. Preferably also width and height. The css properties can either be set in a class in the style sheet or adding them to the Style collection. --- b { font-weight: normal; }

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups