Monday, April 13, 2009

Calendar Extender and TextBox set to ReadOnly in C#

If you are using calendar extendar along with a textbox to get the calendar's date then one of the things that you may want to try is to restrict the user from entering into the text box directly. One simple way to do that is to set readonly property to true. However, when you do that, the value does not become available in the code-behind of the page. One of the solutions is given below,

Put onKeyPress = "javascript: return false;" onPaste = "javascript: return false;" in your textbox. That way, even the textbox is enabled, the user will not be able to modify the data.

To find more about other solutions and issues faced by other users, you can read the thread below:


  1. onKeyPress did not work for me in IE8, however onKeyDown did.