Tuesday, January 16, 2007

TextBox Web Control Readonly Problem ASP.NET 2.0

We noticed a problem today at work where we have readonly text fields that can only be updated by using a calendar as end users have problems entering a date in a correct format.

We had achieved this in asp.net 1.1 by setting the readonly property to true of a textbox web control.

We discovered that none of our calendars were working. Ahhhhh :-(. Fingers started at pointing at the move from asp.net 1.1 to 2.0. In fact it was. asp.net 2.0 has changed the implementation of the textbox web control, if you set the readonly property to true it now stops the controls value to ever be updated.

We have worked around the problem by using a html input control rather than adding code to add the readonly attribute.

1 comments:

Anonymous said...

Hi jims

I just had same problem on a recently-updated-to-.net 2.0 web application.

I figured out a workaround, where i use
myTextBox.Attributes.Add("readonly", "true");

instead of
myTextBox.ReadOnly = true;

Ofcause the drawback here is that we don't get any of the browser compatabillity that the TextBox control implements.
IE and Firefox tested.