webforms - Grabbing values from Ajax AutoCompleteExtender with "Tab" or "Enter" -
i have setup user can come in zip code asp.net textbox
control, , have autocompleteextender
ajax command toolkit attached textbox. gets info static page method on aspx page.
when user starts typing swiss zip code, e.g. 3
, waits brief moment, list of matching zip code shows - like:
3000 - bern 3001 - bern
and on. works charm.
the normal way pick 1 of options shown move mouse pointer list , select 1 want, click on or press enter, , zip code textbox (and city name sec textbox next it).
now, got additional requirements project manager:
we able press enter without going list of choices select 1 - he'd first (or times: only) entry shown set 2 textboxes...
we able come in valid 4-digit zip code , press tab , move out of textbox zipcode, , have first (possibly only) entry zipcode chosen , "selected" (and stuffed 2 textboxes).
seems tall order me (i'm not great javascript guru @ all.....) - ideas?
this asp.net page (in standard asp.net 4.0 webforms sample app - master page; the script simplified; in reality, i'm splitting text 3001 - bern
@ dash , stick first part zip code , sec part city textbox):
<asp:content id="bodycontent" runat="server" contentplaceholderid="maincontent"> <script type="text/javascript"> function iamselected(source, eventargs) { $get('tbxcity').value = eventargs.get_value(); } </script> <asp:scriptmanager runat="server" enablepagemethods="true" /> <asp:literal runat="server" id="litprompt" text="please come in zip code: " /> <asp:textbox runat="server" id="tbxzipcode" maxlength="10" /> <act:autocompleteextender runat="server" id="aczipcode" targetcontrolid="tbxzipcode" minimumprefixlength="1" completioninterval="25" servicemethod="getmatchingzipcodes" completionsetcount="15" onclientitemselected="iamselected" /> <asp:textbox runat="server" id="tbxcity" maxlength="50" /> </asp:content>
and code-behind (this, too, simplified - of course, in reality, info entity framework info model):
[webmethod] [scriptmethod] public static string[] getmatchingzipcodes(string prefixtext, int count) { homecoming new string[] { "3000 - bern", "3001 - bern", "4000 - basel", "6000 - lucerne", "6001 - lucerne" }; }
check firstrowselected
property of autocompleteextender. requirements seems it's need.
webforms ajaxcontroltoolkit asp.net-4.0 autocompleteextender
No comments:
Post a Comment