public knowledge blog_load(sender Virendra)

                                                                                                                          Nothing shocks me, I am a Software Engineer.

ReadOnly and Enabled property of TextBox

Posted by Virendra Dugar on February 6, 2009

One of thing about textbox that confuses me is the Enabled and ReadOnly Property. Both the property makes the text content non editable but there are couple of differences in the way they work.  Here they are:-

Difference No. 1

When we use Enabled Property to false, Textbox’s text is grayed out and we cannot focus on the control and when we use ReadOnly property to true then you will see that the textbox’s content is not grayed out but the content is non editable. 

Difference No. 2

When Enabled = “false” is used, control renders the HTML element as disabled=”disabled” and in case of ReadOnly=”true” then the HTML element is readonly=”readonly”.

I have read on some blogs that disabled controls values are not sent back to the server on postback but that’s not true. If you have disabled any control on client side then only its value will not be sent back to the server. Disabling on client side means either through JavaScript or by adding attributes to the control like

txt.Attributes.Add(“disabled”, “disabled”);

Enjoy…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: