AJAX ComboBox And Backspace/Delete key

In AJAX ComboBox after selecting an item , when user hits Backspace or delete key from the keyboard, an exception is raised.The following snippet does it without modifying the Toolkit’s js file. Hope this helps.

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<script language="javascript" type="text/javascript">
  function pageLoad(sender, args) {
   if (!args.get_isPartialLoad()) {
    var ComboBoxCtrl = $find('ComboBox1');
    var txtVal = ComboBoxCtrl.get_textBoxControl().value;
    var code = ComboBoxCtrl._getKeyboardCode(args);
    if ((txtVal.innerHTML != "") &&
        //(code == Sys.UI.Key.backspace || code == Sys.UI.Key.del) &&
        (ComboBoxCtrl._highlightedIndex == null ))
      {
          ComboBoxCtrl._highlightedIndex = 0;
       }
   }
}
</script>
<div>
<ajaxToolkit:ComboBox runat="server" ID="ComboBox1" MaxLength="100" AutoCompleteMode="Suggest">
<asp:ListItem Text="ABCaaa" Value="ABC"></asp:ListItem>
<asp:ListItem Text="XYZbbbb" Value="XYZ"></asp:ListItem>
</ajaxToolkit:ComboBox>&nbsp;
<asp:Button ID="btnsubmit" runat="server" Text="Add" OnClientClick="" onclick="btnsubmit_Click"/>
</div>
</form>
</body>
</html>

Advertisements
This entry was posted in AJAXToolKit. Bookmark the permalink.

One Response to AJAX ComboBox And Backspace/Delete key

  1. TK says:

    Very useful. Wonder what the commented-out code is for.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s