Problem:
I use a Dynamic RadComboBox having EnableLoadOndemand feature. After entering the search value , I tab out to go to the next control. Sometimes when I tab out, the drop down does not close .
Other Details: I tried using OnClientBlur event to close Dropdown, does not work.
It appears that when the RadComboBox_ItemsRequested server event is being processed, the key stroke (in my case tab) is not being grabbed/recognized. At all other times , the drop down closes.
Code:
I use a Dynamic RadComboBox having EnableLoadOndemand feature. After entering the search value , I tab out to go to the next control. Sometimes when I tab out, the drop down does not close .
Other Details: I tried using OnClientBlur event to close Dropdown, does not work.
It appears that when the RadComboBox_ItemsRequested server event is being processed, the key stroke (in my case tab) is not being grabbed/recognized. At all other times , the drop down closes.
Code:
Public Class TempComboBox Inherits RadComboBox Const BACK_SPACE = "8" Private Sub CompanyInfoComboBox_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init Dim oHeaderTemplate Dim oItemTemplate Me.Height = 200 Me.EnableTextSelection = True Me.MarkFirstMatch = False Me.EnableViewState = True Me.DropDownWidth = 500 Me.OnClientDropDownOpening = "DropDownOpening" Me.EmptyMessage = "Type Code" Me.EnableLoadOnDemand = True Me.ShowMoreResultsBox = False Me.ShowDropDownOnTextboxClick = True Me.HighlightTemplatedItems = True Me.OnClientItemsRequested = "HighlightItem" Me.OnClientItemsRequesting = "HandleKeyPress" Me.OnClientKeyPressing = "HandleTab" Me.OnClientFocus = "HandleOnFocus" Me.CloseDropDownOnBlur = True Me.ChangeTextOnKeyBoardNavigation = True Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikHandleKeyPressScript", TelerikHandleKeyPressScript()) Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikHandleTabScript", TelerikHandleTabScript()) Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikDropDownOpeningScript", TelerikDropDownOpeningScript()) Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikHandleOnFocusScript", TelerikHandleOnFocusScript()) Page.ClientScript.RegisterStartupScript(Me.GetType, "TelerikHighlightItemScript", TelerikHighlightItemScript()) AddHandler Me.ItemsRequested, AddressOf RadComboBox_ItemsRequested oHeaderTemplate = New MasterHeaderTemplate oItemTemplate = New MasterItemTemplate Me.Width = 75 Me.HeaderTemplate = oHeaderTemplate Me.ItemTemplate = oItemTemplate End Sub Function TelerikHighlightItemScript() As String Dim sJscript As String = "<script language=""javascript""> " & _ " function HighlightItem(combo,e){" & _ " var item=combo.get_items().getItem(0); " & _ " if (item){ " & _ " if (item.get_value() != '0'){ " & _ " item.highlight() ; " & _ " } } " & _ " } </script>" Return sJscript End Function Function TelerikDropDownOpeningScript() As String Dim sJscript As String = "<script language=""javascript""> " & _ " function DropDownOpening(combo,e){" & _ " combo.requestItems(combo.get_text(), false); " & _ " } </script>" Return sJscript End Function Function TelerikHandleTabScript() As String Dim sJscript As String = "<script language=""javascript""> " & _ " function HandleTab(combo,e){" & _ " if (event.keyCode == 9) { " & _ " combo.hideDropDown(); " & _ " if (combo.get_value() == ''){" & _ " if (combo.get_items().get_count() > 0){" & _ " combo.set_value(combo.get_text()); } else { combo.set_value(combo.get_text()); } } }" & _ " } </script>" Return sJscript End Function Function TelerikHandleOnFocusScript() As String Dim sJscript As String = "<script language=""javascript""> " & _ " function HandleOnFocus(combo,e){" & _ " var attrib = combo.get_attributes().getAttribute('OriginalFieldID'); " & _ " var firstCombo = $find('FilterType_'+attrib+''); " & _ " if (firstCombo){ " & _ " combo.requestItems(firstCombo.get_value()+'_FilterType', false); } " & _ " } </script>" Return sJscript End Function Function TelerikHandleKeyPressScript() As String Dim sJscript As String = "<script language=""javascript""> " & _ " function HandleKeyPress(combo,e){" & _ " try {if (keypressed == 9) { combo.hideDropDown(); " & _ " }} catch(e) {}" & _ " try {if (keypressed == 8) { var context = e.get_context();" & _ " context[""keyPressed""] = keypressed+''; }} catch(e) {}" & _ " } </script>" Return sJscript End Function Protected Sub RadComboBox_ItemsRequested(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs) If (e.Context.TryGetValue("keyPressed", BACK_SPACE)) Then 'do nothing Else If e.Text.Trim.Length > 3 Then GetDataIntoCombo(e.Text) End If End If End Sub Public Sub GetDataIntoCombo(ByVal txtCode As String) Dim dt As DataTable = GetComboBoxDataFROMDATABASE(txtCode) If dt.Rows.Count = 0 Then Dim item As New RadComboBoxItem() Dim hl As New HyperLink() hl.ID = "hl" hl.Text = " There were no matches. Please click on this link for further information." item.Value = "0" item.DataBind() Me.Items.Add(item) item.DataBind() ElseIf dt.Rows.Count < 51 Then SetDisplayItemsForRefInfo(dt) Dim item As New RadComboBoxItem() item.Text = String.Empty item.Value = "0" Me.Items.Add(item) Else Dim item As New RadComboBoxItem() item.Text = "Too many codes have been found. Please enter more characters." item.Value = "0" Me.Items.Add(item) End If Me.DataBind() End Sub Private Sub SetDisplayItemsForRefInfo(ByVal dt As DataTable) For Each dataRow As DataRow In dt.Rows Dim item As New RadComboBoxItem() Dim Code As String = String.Empty item.Text = DirectCast(dataRow("Code"), String) item.Value = dataRow("Code").ToString() Dim Name As String = String.Empty Try Name = DirectCast(dataRow("Name"), String) Code = DirectCast(dataRow("Code"), String) Catch ex As Exception End Try item.Attributes.Add("Code", Code.ToString) item.Attributes.Add("Name", Name.ToString()) Me.Items.Add(item) item.DataBind() Next End Sub Private Function GetComboBoxDataFROMDATABASE(ByVal UserText As String) As DataTable Try 'code to get from DB Return New DataTable Catch ex As Exception Return Nothing End Try End Function End Class