views:

59

answers:

2

Note: The answer marked as the answer, answers the questions in the Title. However, my underlying problem, using type ahead dropdowns, is solved by moving to IE8.

I have a drop down list that when I CLICK a NEW selection I want to cause a postback ("this.form.submit()") But only if the click on the dropdown list just changed the selection.

Note that OnChange will NOT work because when the selection is changed by the keyboard I would not want to postback because it is a type ahead dropdown list.

I also suppose I could use OnChange and check if the change was caused by the mouse.

Maybe if we can come up with both solutions and i'll see which works better?

Thanks so much for your help!!!!!

EDIT: More information:

AutoPostback = true; will not work. (don't want it to post back when the selection is changed by the keyboard)

onBlur = doPostBack; I tried this, but the result is not optimal. The user has to click off the ddl after making a selection with the mouse.

Another way to state what I want to do, i think, is do a postback when both the OnChange and OnClick events fire at the same time.

A: 

Did you try AutoPostBack="true" ?

matt-dot-net
unfortunalty this will not work for the same reason that just using the OnChange event wont work. The type ahead dropdown changes selection every time the user enters a letter as they are typing. This would fire the autopostback and onChange events unwantedly.
kralco626
well, every time the user enters a letter your AJAX is firing events anyway. Would adding an eventhandler to onblur accomplish what you are looking for? onblur="__doPostback...."
matt-dot-net
Not using AJAX. I tried using onblur, but it does not fire untill the user clicks off the ddl. So the user would click the selection and then sit there and wait and nothing would happen. Essencially I want to post back if both the onChange and onClick events are fired at the same time.
kralco626
what is a "type ahead dropdownlist?"
matt-dot-net
It's like a combo box in access. After the ddl has focus you can type in the selection you want and after each keystoke javascript takes you to the closest option. Its really helpfull with ddls that may have tens of thousands of options.
kralco626
Is this some third party control? I don't understand the difference between what you've described and a basic dropdownlist in a modern browser.
matt-dot-net
kralco626
IE7, IE8, Firefox 3 all do this without any javascript
matt-dot-net
AWESOME! wow, i didn't know that! I developed this on IE6 which did not. So I never thought to check to see if IE8 did when my company upgraded all internal systems to IE8 a month or two ago! Thats so awesome! But for anyone using IE6 still, using that script and the events I posted in my answer should work for you.
kralco626
@matt - Thanks so much for your help!
kralco626
A: 

On the OnClick event I have javascript that sets the ddl.value = true;

On the OnChange event I check to see if ddl.Value = true if so I postback and set it to false.

On the OnKeyDown I set ddl.Value = false so that when I click on the ddl it only posts back if I change the selection with the mouse, if I press a key to use the type-ahead-feature it will not postback.

Not the most elegant solution but it works and you have to give me creadit for creativity.

Note: This solution work in combination with a script that fires on OnKeyDown that runs the type-ahead-ddl(ie. moves you to the closest selection when you press a key) and postsback when you press enter.

kralco626
It was asked elsewhere in this thred so I'll define a "type-ahead-dropdown" a taddl (type-ahead-drop-down-list) is like an access combo box. When you type 'A' it brings you to the As, but when you type a second character 'B' rather than bringing you to the 'B's as is the normal ddl funcationality, it brings you to the 'AB's.
kralco626