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
  1. Home
  2. Web Development
  3. ASP.NET
  4. CSS help

CSS help

Scheduled Pinned Locked Moved ASP.NET
helpcssarchitecture
6 Posts 3 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.
  • J Offline
    J Offline
    jcrussell
    wrote on last edited by
    #1

    I've got a style sheet for my aspx page, and I set the cssClass for my linkbuttons there. My cssClass has a :hover extension so that the appearance of my link button changes when the mouse hovers over it. This all works ok. My problem is that I am trying to do the same thing with textboxes, trying to make them change when the mouse hovers over them. This is where my problem lies because it doesn't do anything... Is this just because they are textboxes or am I doing something wrong .myTextbox:Active /* doesn't work: I wanted the textbox background to change color when it has focus */ { background-color:Lime; } .myTextbox { font-family:Arial, Verdana, Tahoma; font-size:12px; background-color:White; border-style:solid; border-color:"#7F9DB9"; border-width:1; } /jason

    S 1 Reply Last reply
    0
    • J jcrussell

      I've got a style sheet for my aspx page, and I set the cssClass for my linkbuttons there. My cssClass has a :hover extension so that the appearance of my link button changes when the mouse hovers over it. This all works ok. My problem is that I am trying to do the same thing with textboxes, trying to make them change when the mouse hovers over them. This is where my problem lies because it doesn't do anything... Is this just because they are textboxes or am I doing something wrong .myTextbox:Active /* doesn't work: I wanted the textbox background to change color when it has focus */ { background-color:Lime; } .myTextbox { font-family:Arial, Verdana, Tahoma; font-size:12px; background-color:White; border-style:solid; border-color:"#7F9DB9"; border-width:1; } /jason

      S Offline
      S Offline
      Subrahmanyam K
      wrote on last edited by
      #2

      Hi Jason! CSS alone won't produce the required results in all situations, where you need to go for DHTML (CSS with some scripting languages). I hope the following code works for your requirement. Define a function in javascript which takes two parameters: 1. A reference to the control which is calling the function 2. The color you want to apply to the textbox when the mouseovers. function ChangeColor(txt,color) { txt.style.background=color; } Add attributes to the required textboxes in the page_load() event of your code behind file as follows: txtbox.Attributes.Add("onmouseover","ChangeColor(this,'pink');"); txtbox.Attributes.Add("onmouseout","ChangeColor(this,'white');"); Run and text your .aspx. Happy Programming! Subrahmanyam.

      J 1 Reply Last reply
      0
      • S Subrahmanyam K

        Hi Jason! CSS alone won't produce the required results in all situations, where you need to go for DHTML (CSS with some scripting languages). I hope the following code works for your requirement. Define a function in javascript which takes two parameters: 1. A reference to the control which is calling the function 2. The color you want to apply to the textbox when the mouseovers. function ChangeColor(txt,color) { txt.style.background=color; } Add attributes to the required textboxes in the page_load() event of your code behind file as follows: txtbox.Attributes.Add("onmouseover","ChangeColor(this,'pink');"); txtbox.Attributes.Add("onmouseout","ChangeColor(this,'white');"); Run and text your .aspx. Happy Programming! Subrahmanyam.

        J Offline
        J Offline
        jcrussell
        wrote on last edited by
        #3

        Thanks a lot for your code Subrahmanyam, it did the job nicely Subrahmanyam_K wrote: CSS alone won't produce the required results in all situations Any idea why this would be? the code works for a link button, but not for a textbox. Is it just because they are two different types of asp.net control? Thanks again /jason

        S 1 Reply Last reply
        0
        • J jcrussell

          Thanks a lot for your code Subrahmanyam, it did the job nicely Subrahmanyam_K wrote: CSS alone won't produce the required results in all situations Any idea why this would be? the code works for a link button, but not for a textbox. Is it just because they are two different types of asp.net control? Thanks again /jason

          S Offline
          S Offline
          Subrahmanyam K
          wrote on last edited by
          #4

          Hi Jason, If you observe while using CSS, The Anchor Tag can be associated with some styles say(A:Hover, A:Visited etc..) for use in CSS. So, those styles will be applied for all the anchor tags on the page. Whereas, the other HTML Elements do not. We need to use some scripting langauge to make the other HTML elements interactive. And the main point here is that when an asp:linkbutton is used in your .aspx page, this will render an HTML anchor tag. So, any styles defined for the anchor tag will be applied. But, an asp:textbox renders in an HTML tag. To achieve the same for the other controls, we have to add attributes to the ASP.NET Server controls in our HTML file or Code behind file. Thank You, Subrahmanyam.

          J 1 Reply Last reply
          0
          • S Subrahmanyam K

            Hi Jason, If you observe while using CSS, The Anchor Tag can be associated with some styles say(A:Hover, A:Visited etc..) for use in CSS. So, those styles will be applied for all the anchor tags on the page. Whereas, the other HTML Elements do not. We need to use some scripting langauge to make the other HTML elements interactive. And the main point here is that when an asp:linkbutton is used in your .aspx page, this will render an HTML anchor tag. So, any styles defined for the anchor tag will be applied. But, an asp:textbox renders in an HTML tag. To achieve the same for the other controls, we have to add attributes to the ASP.NET Server controls in our HTML file or Code behind file. Thank You, Subrahmanyam.

            J Offline
            J Offline
            jcrussell
            wrote on last edited by
            #5

            This is what I am interested in, do you know where I can get a list of controls that are anchors and which aren't? Subrahmanyam_K wrote: we have to add attributes to the ASP.NET Server controls in our HTML file or Code behind file. is this just controlName.attributes.add("attributeName") = attributeValue? if so how would you use this to make it an anchor? sorry to ask so many questions, but this is interesting to me...sad isn't it? :^) /jason

            L 1 Reply Last reply
            0
            • J jcrussell

              This is what I am interested in, do you know where I can get a list of controls that are anchors and which aren't? Subrahmanyam_K wrote: we have to add attributes to the ASP.NET Server controls in our HTML file or Code behind file. is this just controlName.attributes.add("attributeName") = attributeValue? if so how would you use this to make it an anchor? sorry to ask so many questions, but this is interesting to me...sad isn't it? :^) /jason

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Jason! We can not modify the server controls to render anchor elements. The rendering process will be done by ASP.NET as how the server controls are developed to render. What we should check is the equivalent HTML control for all the server controls after rendering. Then we can program to make the rendered HTML controls interactive by adding attributes in the code behind file. Try developing a small Custom control, so that you will be clear how the server controls work. Some good examples are provided in Online MSDN. And this is how Attributes are added to the Server controls in the code behind file: ControlName.Attributes.Add("AttributeName","AttributeValue"); Happy Programming! :) Subrahmanyam.

              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