Friday, November 13, 2009

Stranges Behavior with AutoCompleteExtender

Two odd behaviors with AutoCompleteExtenders I wanted to jot down before I forget.
If have want to set the focus on the textbox bound to the AutoCompleteExtender using JavaScript code (on pageLoad for example), the AutoCompleteExtender won't work

here's more on this and a solution
http://forums.asp.net/t/1397904.aspx

and here http://forums.asp.net/t/1220054.aspx

The other odd behavior is I think when we have a textbox with AutoCompleteExtender, the page tries to find the first input element with type = "submit" and selects such that if you hit enter that button will be clicked. I am not 100% sure, but I ran into this today.

I got around this by adding UseSubmitBehavior="false" property to all the buttons in the page. Doing so cause a problem, because some buttons had OnClientClick property populated and when their UseSubmitBehavior property set to false, they stopped submitting the form. The work around here is to submit the form using JavaScript code for example

asp:Button id="btnNew" runat="server" UseSubmitBehavior="false"
OnClientClick="if(validateForm()) this.form.submit();"

No comments:

Post a Comment