This is a cautionary note for web developers using the Microsoft ASP.Net AJAX framework and the AJAX Control Toolkit.
Imagine this scenario: you have a web page where the user picks a date from a calendar, then you use that date to select a set of records from a database to display in a table on the same page. Fairly straightforward, you would have thought.
The calendar comprised of a TextBox and the CalendarExtender from the AJAX Control Toolkit. On selecting a date in the calendar, the value is displayed in the TextBox. This would trigger a postback which would allow me to grab the date and use it to retrieve the records from the database.
No matter what I tried, the postback was not being triggered. After much research, I finally got it working but was surprised to discover that the root cause of the problem lay with the TextBox:
Code Snippet
- <asp:TextBox ID="txtSelectedDate" ReadOnly="true" />
Apparently, if a TextBox is set to be read-only, then it does not fire an OnTextChanged event on postback.
The solution was to remove the read-only attribute and use client-side JavaScript to prevent the TextBox from being edited.