Tag: css

  • ASP.NET Webforms Disabled vs Readonly Fields

    ASP.NET Webforms Disabled vs Readonly Fields

    ASP.NET Webforms has two ways of disabling text input fields:

    Method 1: Disabled

    
    
    
    

    Method 2: ReadOnly

    
    
    
    

    The first method greys out the field by default, the second one does not grey out. The other difference I have found is that the second method leaves the scroll bar in memo fields enabled, as opposed to disabling it (although its still possible to move around with the cursor keys in both cases).

    So here is some CSS that can be used to help make it look consistent:

    
    /* This is used when Enabled="False" */
    .aspNetDisabled
    {
        background-color: #f9f9f9;
        color: #666666;
    }
    
    /* This is used when any textboxes are ReadOnly="True" */
    input[readonly] {
        background-color: #f9f9f9;
        color: #666666;
    }
    
    /* This is used when any multi-line textboxes are ReadOnly="True" */
    textarea[readonly]{
        background-color: #f9f9f9;
        color: #666666;
    }