This is a migrated thread and some comments may be shown as answers.

[Solved] WebMethod - too many calls

8 Answers 175 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Andrea Doberstein
Top achievements
Rank 1
Andrea Doberstein asked on 27 Jan 2010, 02:51 PM
HI,
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

Sort by
0
Simon
Telerik team
answered on 28 Jan 2010, 02:03 PM
Hi Andrea Doberstein,

The WebMethod should be called once per Items request. The behavior you are experiencing is not normal.

Can you please describe in more detail when exactly does this happen? Can you reproduce it each time?

Finally please confirm that you are using Telerik.Web.UI 2009.3 1314 and not other version.

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.
0
Andrea Doberstein
Top achievements
Rank 1
answered on 28 Jan 2010, 02:35 PM
Hi,
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");  
      
}  
 
Thanks,
Andrea
0
Simon
Telerik team
answered on 01 Feb 2010, 10:37 AM
Hello Andrea Doberstein,

Thank you for providing your code.

It does not have anything suspicious that may be causing the issue. Perhaps this is a bug in the version you are using.

Can you please describe in more details what exactly happens when you click in the second RadComboBox? For instance, the drop down opens, items are loaded, then more items are loaded a second time or there seems to be only one request, i.e. items are shown in the drop down once, however two Web Service requests are made.

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.
0
Andrea Doberstein
Top achievements
Rank 1
answered on 01 Feb 2010, 03:46 PM
Hi Simon,
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

0
Andrea Doberstein
Top achievements
Rank 1
answered on 08 Feb 2010, 02:14 PM
Hello?
0
Simon
Telerik team
answered on 09 Feb 2010, 10:39 AM
Hi Andrea Doberstein,

Thank you for the extensive debug information.

The two consecutive Items requests by themselves point to an issue inside RadComboBox' Load On Demand. However the other two exceptions - the server and client-side - are rather suspicious.

In order to determine the cause or the causes of these errors I will need to debug/investigate the whole process.

In this sense, please prepare the simplest project possible that still shows the errors (you can use a dummy data source and remove any code dependencies or supply them) and send it to us via a support ticket. You can also mention this forum thread, so that we have some background information about the issue.

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.
0
Andrea Doberstein
Top achievements
Rank 1
answered on 09 Feb 2010, 12:48 PM
Hi Simon,
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); 
But in the demo project I used
List<RadComboBoxItemData> items = new List<RadComboBoxItemData>(); 

Hope this will help you.
Thanks, Andrea
0
Simon
Telerik team
answered on 10 Feb 2010, 01:19 PM
Hello Andrea Doberstein,

Thank you for providing the project.

Please let us continue our communication in the support ticket from now on. 

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.
Tags
ComboBox
Asked by
Andrea Doberstein
Top achievements
Rank 1
Answers by
Simon
Telerik team
Andrea Doberstein
Top achievements
Rank 1
Share this question
or