...the problem is, if your focus change *is* your submit button. A quick search of ontextchanged onblur, shows many creative solutions. You can add some messy javascript and have a timer run after the person is idle for a few seconds. What I wound up doing is disabling my submit button. Then I added autopostback="true" to all the controls in my form -- textboxes (OnTextChanged), DropDownList (OnSelectedIndexChanged), CheckBoxes (OnCheckChanged). Then, each event handler sets the visibility of the submit button to visible. So when a person is using a form, they see "Update" but it's grayed out. "Hmm. Why can't I click that?" they ask. Well, because you haven't changed anything yet. So they change something in a textbox (which is going to affect something in another textbox; hence the need for the OnTextChanged so you can update that other textbox). Nothing happens. Perhaps they'll hit enter (which you may need to handle as textboxes don't handle the enter key by default, but that's for a different post). Perhaps, they will try clicking that grayed out Update button again. "Well, I updated something, but the button is still grayed out, but I have nothing else to try, so I'll try clicking it again anyway". That click action is just the focus change that your textbox needed. So now the page posts back, the other textboxes update, and now your update button is set to visible. So now your update button is just asking to be clicked, so your update can be done. Suffice it to say all of this is best done inside an Ajax UpdatePanel; otherwise the page reload of the standard postback might be confusing to the person. In my case, I have this all going on inside a modal popup, which has a cancel button which is visible the entire time. So it's pretty obvious that the Update button has to be enabled for the actual update to occur. If the person types in the textbox, and then just sits there, nothing is going to happen. So they'll either click Cancel, which will of course cancel; and the lack of the data updating should obviously show them nothing happened. Or they will change to a different field (which will fire the OnTextChanged), or they will try clicking that disabled update button (which will fire the OnTextChanged).
Technorati tags:
OnTextChanged