Difference between disabled and read only attributes In Asp.Net


Disabled attribute


  • Disabled form fields or elements values don’t post to the server for processing.
  • Disabled form fields or elements don’t get focus.
  • Disabled form fields or elements are skipped while tab navigation.
  • Some browsers (Like IE) provide default style (Gray out or emboss text) for disabled form fields or elements.


Read Only Attribute


  • Read Only form fields or elements values post to the server for processing.
  • Read Only form fields or elements get focus.
  • Read Only form fields or elements are included while tab navigation.
  • Some browsers do not provide default style for Read-Only form fields or elements.


Set Disabled Attribute


ASP.NET TextBox
  • <asp:TextBox ID="txtDisabled" Enabled="false" runat="server"></asp:TextBox>

HTML Input
  • <input name="txtDisabled" type="text" id="txtDisabled" disabled="disabled"/>


Set Read Only Attribute

ASP.NET TextBox
<asp:TextBox ID="txtReadonly" ReadOnly="true" runat="server"></asp:TextBox>

HTML Input
<input name="txtReadonly" type="text" id="txtReadonly" readonly="readonly"/>


CSS For read only and disabled attribute input element

Since some browser don’t provide default style for disabled element. Hence to display disabled elements on all browsers in same look and feel, we can use below css.

input[disabled]{background-color:#F0F0F0; color:#303030;}

Similarly we can change the look and feel of readonly element by using below css.

input[readonly]{background-color:#F0F0F0 ;color:#303030 }



0 Comments