John's profileJohn BarshingerPhotosBlogLists Tools Help

Blog


    April 23

    asp Checkbox css style on the input element

     
    when ASP.NET renders an <asp:Checkbox... /> it renders HTML similar to this:
     
    <span><input type="checkbox" ... /></span>
     
    When you want to specify the height of the checkbox for example. You would think something like this would do the trick:
     

    checkBox.Height = Unit.Pixel(12); // this is needed for IE8

    This actually does the trick for IE8 but not for IE6. Now this is rendered:
     
    <span style="display:inline-block;height:12px;"><input type="checkbox" ...  /></span>
     
    For IE6, the following code must be used:
     

    button.InputAttributes[

    "style"] = "height: 12px"; // this is needed for IE6
    button.InputAttributes["height"] = "12px"; // this is needed for IE6
    button.Height = Unit.Pixel(12); // this is needed for IE8

    This actually does the trick for both IE8 and IE6. Finally this is rendered:

    <span style="display:inline-block;height:12px;"><input type="checkbox" height="12px" ... /></span>

    This was a PIA for me to figure out, I hope this helps you if you run into a similar formatting issue with ASP.NET Checkbox controls.