locked
Hover-Style for single elements of a new control RRS feed

  • Question

  • User-536615835 posted

    Hi,

    I've a UserConrol, lets say ButtonX with several parameters like color, text and border. This parameters are passed to different elements of my control, e.g., the text to an asp:Label and the border to the style attribute of an enclosing DIV. No I want to pass some parameter to the hover and active state of some inner control elements (e.g., the DIV). I know how to set every CSS style parameter of an asp:Label or DIV - but how can I set the hover parameters?

    I can not write an external CSS class like

    .button1:hover { ... } and assign this, because the color is assigned dynamically via the UserControl like <xy:ButtonX id=".." hoverColor="..." runat="server"/>

    Thus, how can I change the hover parameters in my C# code behind dynamically?

     

    Many Thanks

    Konrad

    Thursday, May 5, 2011 9:20 AM

Answers

  • User-16411453 posted

    sometimes, certain css does not work in ie, but works on firefox and sarfari.

    So I just use javascript now to change colors,I use the first one, the second one, I didn't have enough time to mess with it and test it fully.

    function containerColorII(containerName, bgColor) {
        containerName.style.backgroundColor = bgColor;
    }

    function changeColor(id, color) {
    element = document.getElementById(id);
    event.cancelBubble = true;
    oldColor = element.currentStyle.background;
    element.style.background = color;
    }

    Dim panel_Display_MovieSquares_ContainerCell_Wrapper As Panel
    panel_Display_MovieSquares_ContainerCell_Wrapper = New Panel
    With panel_Display_MovieSquares_ContainerCell_Wrapper
    '.Attributes.Add("id", "_containerCellWrapper" & movie_ID)
    .ID = [ID] & "_panel_Display_MovieSquares_ContainerCell_Wrapper_" & movie_ID.ToString
    .Style.Add(HtmlTextWriterStyle.BackgroundColor, [DisplayContainer_BGColor])

    If [Container_PaintMode] = True Then
    .Attributes.Add("onMouseOver", "containerColorII(this, '" & [Container_BGColor_MouseOver] & "');")
    .Attributes.Add("onMouseOut", "containerColorII(this, '" & [DisplayContainer_BGColor] & "');")
    End If

    End With
    td_Display_MovieSquares_ContainerCell.Controls.Add(panel_Display_MovieSquares_ContainerCell_Wrapper)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 6, 2011 6:35 PM

All replies

  • User-16411453 posted

    you use javascript and the onmouseover event, or make a css class with the hover and assign it to the object.

    Thursday, May 5, 2011 4:11 PM
  • User-536615835 posted

    Did I understand right?: I've to create the CSS-code dynamically for each object in the C# code and include it at the top of the page, refering with a distinct ID?

    Friday, May 6, 2011 3:38 AM
  • User-16411453 posted

    sometimes, certain css does not work in ie, but works on firefox and sarfari.

    So I just use javascript now to change colors,I use the first one, the second one, I didn't have enough time to mess with it and test it fully.

    function containerColorII(containerName, bgColor) {
        containerName.style.backgroundColor = bgColor;
    }

    function changeColor(id, color) {
    element = document.getElementById(id);
    event.cancelBubble = true;
    oldColor = element.currentStyle.background;
    element.style.background = color;
    }

    Dim panel_Display_MovieSquares_ContainerCell_Wrapper As Panel
    panel_Display_MovieSquares_ContainerCell_Wrapper = New Panel
    With panel_Display_MovieSquares_ContainerCell_Wrapper
    '.Attributes.Add("id", "_containerCellWrapper" & movie_ID)
    .ID = [ID] & "_panel_Display_MovieSquares_ContainerCell_Wrapper_" & movie_ID.ToString
    .Style.Add(HtmlTextWriterStyle.BackgroundColor, [DisplayContainer_BGColor])

    If [Container_PaintMode] = True Then
    .Attributes.Add("onMouseOver", "containerColorII(this, '" & [Container_BGColor_MouseOver] & "');")
    .Attributes.Add("onMouseOut", "containerColorII(this, '" & [DisplayContainer_BGColor] & "');")
    End If

    End With
    td_Display_MovieSquares_ContainerCell.Controls.Add(panel_Display_MovieSquares_ContainerCell_Wrapper)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 6, 2011 6:35 PM