I'm using 5 RadComboBoxes with WebServices and it works fine. But sometimes the WebMethods are called two times (with exactly the same context value). Is this a normal behavior or am I doing something wrong? I would like to optimize the WebMethods as optimized as possible because it's making an sql select in an oracle db. This selects are very big and it spends some seconds to retrieve the results.
Thanks,
Andrea
All RadComboBoxes are build in this way:
| <td style="width: 275px;"> |
| <telerik:RadComboBox ID="radComboBoxStr" runat="server" Width="250px" DropDownWidth="260px" |
| AutoPostBack="true" MaxHeight="200px" EnableLoadOnDemand="true" MarkFirstMatch="false" |
| ShowMoreResultsBox="true" OnSelectedIndexChanged="radComboBoxStr_SelectedIndexChanged" |
| EnableVirtualScrolling="true" ChangeTextOnKeyBoardNavigation="false" OnClientItemsRequesting="OnClientItemsRequesting" |
| OnClientItemsRequested="OnClientItemsRequested" OnClientDropDownOpening="OnClientDropDownOpening" |
| EnableItemCaching="true" TabIndex="3"> |
| <HeaderTemplate> |
| <table id="ResultsHeadersStr" style="width: 200px;"> |
| <tr> |
| <td class="column" style="width: 200px;"> |
| <b> |
| <asp:Literal ID="litStrasse" runat="server" Text="<%$ Resources:Language, combobox_Strasse %>"></asp:Literal></b> |
| </td> |
| </tr> |
| </table> |
| </HeaderTemplate> |
| <WebServiceSettings Method="GetItemsStr" Path="ComboBoxWebService.asmx" /> |
| </telerik:RadComboBox> |
| </td> |
8 Answers, 1 is accepted
Greetings,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I'm using the correct version.
I tried to reproduce: I've got one ComboBox "cbPLZ" and one "cbOrt". If I click in cbPLZ only one request is send. That's ok. If I click on the cbOrt than two requests are send. I can't see if I made something wrong.
I send some parts of my code - perhaps you can see some errors?
| ------ |
| AJAX: |
| ------ |
| <td style="width: 85px;"> |
| <telerik:RadComboBox ID="radComboBoxPLZ" runat="server" Width="60px" DropDownWidth="300px" EnableItemCaching="true" |
| AutoPostBack="true" MaxHeight="200px" EnableLoadOnDemand="true" MarkFirstMatch="false" |
| ShowMoreResultsBox="true" OnSelectedIndexChanged="radComboBoxPLZ_SelectedIndexChanged" |
| EnableVirtualScrolling="true" ChangeTextOnKeyBoardNavigation="false" OnClientItemsRequesting="OnClientItemsRequesting" |
| OnClientItemsRequested="OnClientItemsRequested" OnClientDropDownOpening="OnClientDropDownOpening" |
| TabIndex="1" OnClientSelectedIndexChanged="radComboBoxPLZ_OnClientSelectedIndexChanged"> |
| <HeaderTemplate> |
| <table id="ResultsHeadersPLZ" style="width: 260px;"> |
| <tr> |
| <td class="column" style="width: 40px;"> |
| <b> |
| <asp:Literal ID="litPLZ" runat="server" Text="<%$ Resources:Language, combobox_PLZ %>"></asp:Literal></b> |
| </td> |
| <td class="column" style="width: 170px;"> |
| <b> |
| <asp:Literal ID="litPost" runat="server" Text="<%$ Resources:Language, combobox_Poststelle %>"></asp:Literal></b> |
| </td> |
| <td class="column"> |
| <b> |
| <asp:Literal ID="litKanton" runat="server" Text="<%$ Resources:Language, combobox_Kanton %>"></asp:Literal></b> |
| </td> |
| </tr> |
| </table> |
| </HeaderTemplate> |
| <WebServiceSettings Method="GetItemsPLZ" Path="ComboBoxWebService.asmx" /> |
| </telerik:RadComboBox> |
| </td> |
| <td style="width: 275px;"> |
| <telerik:RadComboBox ID="radComboBoxOrt" runat="server" Width="250px" DropDownWidth="500px" |
| AutoPostBack="true" MaxHeight="200px" EnableLoadOnDemand="true" MarkFirstMatch="false" |
| ShowMoreResultsBox="true" EnableVirtualScrolling="true" ChangeTextOnKeyBoardNavigation="false" |
| OnClientItemsRequesting="OnClientItemsRequesting" OnClientItemsRequested="OnClientItemsRequested" |
| OnClientDropDownOpening="OnClientDropDownOpening" OnSelectedIndexChanged="radComboBoxOrt_SelectedIndexChanged" |
| EnableItemCaching="true" TabIndex="2" OnClientSelectedIndexChanged="radComboBoxOrt_OnClientSelectedIndexChanged"> |
| <HeaderTemplate> |
| <table id="ResultsHeadersOrt" style="width: 440px;"> |
| <tr> |
| <td class="column" style="width: 200px;"> |
| <b> |
| <asp:Literal ID="litOrt" runat="server" Text="<%$ Resources:Language, combobox_Ort %>"></asp:Literal></b> |
| </td> |
| <td class="column" style="width: 180px;"> |
| <b> |
| <asp:Literal ID="litGemeinde" runat="server" Text="<%$ Resources:Language, combobox_Gemeinde %>"></asp:Literal></b> |
| </td> |
| <td class="column"> |
| <b> |
| <asp:Literal ID="litKanton2" runat="server" Text="<%$ Resources:Language, combobox_Kanton %>"></asp:Literal></b> |
| </td> |
| </tr> |
| </table> |
| </HeaderTemplate> |
| <WebServiceSettings Method="GetItemsOrt" Path="ComboBoxWebService.asmx" /> |
| </telerik:RadComboBox> |
| ------ |
| JS: |
| ------ |
| function radComboBoxPLZ_OnClientSelectedIndexChanged(sender, eventArgs) |
| { |
| // pre-select the first item |
| var text = eventArgs.get_item().get_value(); |
| if (text != "" && cbOrt != null) |
| cbOrt.set_text(text); |
| } |
| function radComboBoxOrt_OnClientSelectedIndexChanged(sender, eventArgs) |
| { |
| // pre-select the first item |
| var text = eventArgs.get_item().get_value(); |
| if (text != "") |
| cbPLZ.set_text(text); |
| } |
| -------- |
| CS-Web: |
| -------- |
| [WebMethod] |
| public RadComboBoxData GetItemsPLZ(RadComboBoxContext context) |
| { |
| string sqlSelectCommand = string.Format("Select distinct p.PLZ, p.Poststelle, k.Kanton from {0}", SQL_FROM_SMALL); |
| //alle Werte auslesen |
| Hashtable htabValues = GetControlValues(context); |
| if (!string.IsNullOrEmpty(context.Text)) |
| sqlSelectCommand += string.Format(SQL_WHERE_PLZ, context.Text); |
| if (!string.IsNullOrEmpty(htabValues["ORT"].ToString())) |
| sqlSelectCommand += string.Format(SQL_WHERE_ORT, htabValues["ORT"]); |
| if (!string.IsNullOrEmpty(htabValues["GEM"].ToString())) |
| sqlSelectCommand += string.Format(SQL_WHERE_GEM, htabValues["GEM"]); |
| if (!string.IsNullOrEmpty(htabValues["KAN"].ToString())) |
| sqlSelectCommand += string.Format(SQL_WHERE_KANTON, htabValues["KAN"]); |
| sqlSelectCommand += " ORDER BY p.PLZ"; |
| //Abfrage starten |
| DataTable dTable = GetResult("GetItemsPLZ", sqlSelectCommand); |
| List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems); |
| RadComboBoxData comboData = new RadComboBoxData(); |
| try |
| { |
| int itemOffset = context.NumberOfItems; |
| int endOffset = itemOffset + itemsPerRequest; |
| if (endOffset > dTable.Rows.Count) |
| { |
| endOffset = dTable.Rows.Count; |
| } |
| if (endOffset == dTable.Rows.Count) |
| { |
| comboData.EndOfItems = true; |
| } |
| else |
| { |
| comboData.EndOfItems = false; |
| } |
| result = new List<RadComboBoxItemData>(endOffset - itemOffset); |
| for (int i = itemOffset; i < endOffset; i++) |
| { |
| RadComboBoxItemData itemData = new RadComboBoxItemData(); |
| itemData.Text = dTable.Rows[i]["PLZ"].ToString(); |
| string check = GetUniqueOrtByPLZ(dTable.Rows[i]["PLZ"].ToString()); |
| itemData.Value = check; |
| itemData.Attributes["Poststelle"] = dTable.Rows[i]["Poststelle"].ToString(); |
| itemData.Attributes["Kanton"] = dTable.Rows[i]["Kanton"].ToString(); |
| result.Add(itemData); |
| } |
| //Text für Von-Bis Items anzeigen |
| comboData.Message = ShowMessage(endOffset, dTable.Rows.Count); |
| } |
| catch (Exception e) |
| { |
| comboData.Message = e.Message; |
| } |
| comboData.Items = result.ToArray(); |
| return comboData; |
| } |
| [WebMethod] |
| public RadComboBoxData GetItemsOrt(RadComboBoxContext context) |
| { |
| string sqlSelectCommand = string.Format("select distinct p.ORT, k.Gemeinde, k.Kanton from {0}", SQL_FROM_SMALL); |
| //alle Werte auslesen |
| Hashtable htabValues = GetControlValues(context); |
| if (!string.IsNullOrEmpty(htabValues["ORT"].ToString())) |
| sqlSelectCommand += string.Format(SQL_WHERE_ORT, htabValues["ORT"]); |
| if (!string.IsNullOrEmpty(htabValues["PLZ"].ToString())) |
| sqlSelectCommand += string.Format(SQL_WHERE_PLZ, htabValues["PLZ"]); |
| sqlSelectCommand += " order by p.ORT"; |
| //Abfrage starten |
| DataTable dTable = GetResult("GetItemsOrt", sqlSelectCommand); |
| List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(context.NumberOfItems); |
| RadComboBoxData comboData = new RadComboBoxData(); |
| try |
| { |
| int itemOffset = context.NumberOfItems; |
| int endOffset = itemOffset + itemsPerRequest; |
| if (endOffset > dTable.Rows.Count) |
| { |
| endOffset = dTable.Rows.Count; |
| } |
| if (endOffset == dTable.Rows.Count) |
| { |
| comboData.EndOfItems = true; |
| } |
| else |
| { |
| comboData.EndOfItems = false; |
| } |
| result = new List<RadComboBoxItemData>(endOffset - itemOffset); |
| for (int i = itemOffset; i < endOffset; i++) |
| { |
| RadComboBoxItemData itemData = new RadComboBoxItemData(); |
| itemData.Text = dTable.Rows[i]["Ort"].ToString(); |
| itemData.Value = GetUniquePLZByOrt(dTable.Rows[i]["Ort"].ToString(), dTable.Rows[i]["Gemeinde"].ToString()); |
| itemData.Attributes["Gemeinde"] = dTable.Rows[i]["Gemeinde"].ToString(); |
| itemData.Attributes["Kanton"] = dTable.Rows[i]["Kanton"].ToString(); |
| result.Add(itemData); |
| } |
| //Text für Von-Bis Items anzeigen |
| comboData.Message = ShowMessage(endOffset, dTable.Rows.Count); |
| } |
| catch (Exception e) |
| { |
| comboData.Message = e.Message; |
| } |
| comboData.Items = result.ToArray(); |
| return comboData; |
| } |
| ----------------- |
| CS -CodeBehind: |
| ----------------- |
| protected void radComboBoxPLZ_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) |
| { |
| if (radComboBoxOrt.Visible) |
| ScriptManager1.SetFocus(radComboBoxOrt.ClientID + "_Input"); |
| else |
| ScriptManager1.SetFocus(radComboBoxGemeinde.ClientID + "_Input"); |
| } |
| protected void radComboBoxOrt_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) |
| { |
| ScriptManager1.SetFocus(radComboBoxStr.ClientID + "_Input"); |
| } |
Andrea
Best wishes,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
the ComboBoxes are always filled in the right way - items are shown once in the dropdown but two requests are made.
I think, I can reproduce the behaviour - I hope so.
If I click on cbPLZ (Box 1) and enter (for example) "5728" I want to search the item "5728" in cbPLZ and set text "Test" for cbOrt (Box 2). I've got the following trace output:
-------------------------------------------------------------------------------------------------------------------------
TRACE - GetItemsPLZ: Select distinct * from [...] where p.KANT_GEM_ID = k.ID ORDER BY p.PLZ
TRACE - GetItemsPLZ: Select distinct * from [...] where p.KANT_GEM_ID = k.ID AND p.PLZ like ('5728%') ORDER BY p.PLZ
A first chance exception of type 'System.NullReferenceException' occurred in mscorlib.dll
-------------------------------------------------------------------------------------------------------------------------
Now when I click on cbOrt (it's is already filled with the one item) I've got two internal requests:
-------------------------------------------------------------------------------------------------------------------------
TRACE - GetItemsOrt: select distinct * from [...] where upper(p.Ort) like upper('Test%') AND p.PLZ like ('5728%')
TRACE - GetItemsOrt: select distinct * from [...] where upper(p.Ort) like upper('Test%') AND p.PLZ like ('5728%')
A first chance exception of type 'System.NullReferenceException' occurred in mscorlib.dll
-------------------------------------------------------------------------------------------------------------------------
I can also do that in other direction. If I click on cbOrt (Box 2) and enter (for example) "Test" I want to search the item "'Gontenschwil" in cbOrt and set text "5728" for cbPLZ (Box 1). I've got the following trace output:
-------------------------------------------------------------------------------------------------------------------------
A first chance exception of type 'System.NullReferenceException' occurred in mscorlib.dll
TRACE - GetItemsOrt: select distinct * from [...] where p.KANT_GEM_ID = k.ID order by p.ORT
TRACE - GetItemsOrt: select distinct * from [...] where p.KANT_GEM_ID = k.ID AND upper(p.Ort) like upper('Test%') order by p.ORT
-------------------------------------------------------------------------------------------------------------------------
Now when I click on cbPLZ (it's is already filled with the one item) I've got two internal requests:
-------------------------------------------------------------------------------------------------------------------------
A first chance exception of type 'System.NullReferenceException' occurred in mscorlib.dll
TRACE - GetItemsPLZ: Select distinct * from [...] where p.PLZ like ('5728%') AND upper(p.Ort) like upper('Gontenschwil%')
TRACE - GetItemsPLZ: Select distinct * from [...] where p.PLZ like ('5728%') AND upper(p.Ort) like upper('Gontenschwil%')
A first chance exception of type 'System.NullReferenceException' occurred in mscorlib.dll
-------------------------------------------------------------------------------------------------------------------------
Note: If I double-click in one ComboBox (there is already one text set) then I get the following error:
"Microsoft JScript runtime error: 'window' is null or not an object"
It occurs in script:
// Name: MicrosoftAjax.debug.js
// Assembly: System.Web.Extensions
// Version: 3.5.0.0
// FileVersion: 3.5.30729.196
//-----------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------
// MicrosoftAjax.js
// Microsoft AJAX Framework.
[..]
try {
_this._webRequest.completed(Sys.EventArgs.Empty);
}
finally {
if (_this._xmlHttpRequest != null) {
_this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
_this._xmlHttpRequest = null;
}
}
[...]
I don't think that these errors depend on each other - but who knows....
Thanks,
Andrea
Best wishes,
Simon
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
I created a ticket (Number 280241) with a simple small projects.
But now I can only reproduce the duplicate calls of the web methods. The other errors are gone away....
Normally I use following code to generate the RadComboBoxItemData.
| result = new List<RadComboBoxItemData>(endOffset - itemOffset); |
| List<RadComboBoxItemData> items = new List<RadComboBoxItemData>(); |
Hope this will help you.
Thanks, Andrea
Sincerely yours,
Simon
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.