I have gone insane trying to figure out how to make this work. Code looks roughly like:
function onDropDownChanged() {
$("#updatePanel").load(
"myUrl",
{ id: $("#myDropDown option:selected").val() },
onPanelLoaded
);
}
function onPanelLoaded() {
$("#theTextInput").focus();
}
$(document).ready(function() {
$("#myDropDown").change(onDropDownChanged);
}
The first time the change handler is fired, it does the ajax update, and the text box is focused.
However, on subsequent changes, it continues to do the ajax update, but the text box is never focused again.
I found that if in onDropDownChanged
, I added $("#updatePanel").empty()
before the ajax call, the text box would always get focused. The problem with that is the entire form disappears for a second, causing an ugly flash. Given ajax is supposed to make things like this nice, it's not a workaround I want to use.