Saturday, March 24, 2012

CascadingDropDown with a DB causing stack overflow

I've struggled for days through examples and self discovery to get to where I am, and now I get a stack overflow error from my cascadingdropdown object which is attempting to retrieve data from a tableadapter. When the page loads I get a msgbox pop-up error which says: "Stack overflow at line: 116". I've tried commenting out most every line in the webservice function and that seems to have no discernible effect. Perhaps it's something in the aspx page? Any help greatly appreciated.

Here's my aspx:

-------------------------------------------

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %
<%@dotnet.itags.org. Register
Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="ajaxToolKit" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<br />
<br />
<div>
<asp:DropDownList ID="ddl_GetService" runat="server">
</asp:DropDownList> <br />

<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList><br />
<br />
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList><br />
<br />
<br />

<ajaxToolKit:cascadingdropdown id="CascadingDropDown1" runat="server" TargetControlID="ddl_GetService" Category="Service" PromptText="Select a Service Code" ServicePath="wsGetServices.asmx" ServiceMethod="GetAllServices" ParentControlID="ddl_GetService" >
</ajaxToolKit:cascadingdropdown>
<br />
</div>
<br />
<br />
<br />

</form>
</body>
</html>


-------------------------------------------

Here's my asmx file:

-------------------------------------------

<%@dotnet.itags.org. WebService Language="VB" Class="wsGetServices" %
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports AjaxControlToolkit
Imports Facilities_WizardTableAdapters
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.Specialized

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class wsGetServices
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function GetAllServices(ByVal sServRsn As String, ByVal sCode As String) As AjaxControlToolkit.CascadingDropDownNameValue()
Dim ServiceTableAdapter As TBL_WZ_SERVICETableAdapter = Nothing
ServiceTableAdapter = New TBL_WZ_SERVICETableAdapter()
Dim Services As Facilities_Wizard.TBL_WZ_SERVICEDataTable = ServiceTableAdapter.GetServices()
Dim values As List(Of CascadingDropDownNameValue) = New List(Of CascadingDropDownNameValue)
Dim dr As Facilities_Wizard.TBL_WZ_SERVICERow

For Each dr In Services
sServRsn = dr.SERV_RSN.ToString()
sCode = dr.CODE.ToString()
values.Add(New CascadingDropDownNameValue(sServRsn, sCode))
Next dr

Return values.ToArray()

End Function

End Class

I discovered that it's a stack overflow because it's working! And the number of rows returned is rather large. So does anyone know how I can accomodate for that? I mean a drop down with say around 300 entries?

Thanks!


It's not clear to me why returning lots of entries should cause a stack overflow. Maybe run this page under the VS debugger and have a look at what's on the stack at the time - that should help narrow the problem down.

I am having a similar issue today. I know my webservice is working and it only returns 27 records. here is my ASMX file if anyone has any advice:

<%

@.WebServiceLanguage="VB"Class="LHMCSearchDD" %>

Imports

System.Web

Imports

System.Web.Services

Imports

System.Web.Services.Protocols

Imports

System.Collections.Generic

Imports

System.Data

Imports

System.Data.SqlClient

Imports

System.Configuration

Imports

AjaxControlToolkit

<WebService(Namespace:=

"http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<System.Web.Script.Services.ScriptService()> _

Public

Class LHMCSearchDDInherits System.Web.Services.WebService

<WebMethod()> _

PublicFunction GetProducts(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()Dim cadapterAsNew dsSearchTableAdapters._PRODUCTTableAdapter' Dim cadapter As New dsSearch.DSTablesTableAdapters.countryTableAdapterDim ctableAsNew dsSearch._PRODUCTDataTable' Dim ctable As New ltcodebehind.DSTables.countryDataTable

cadapter.FillBrands(ctable)

Dim valuesAsNew List(Of AjaxControlToolkit.CascadingDropDownNameValue)For iAsInteger = 0To ctable.Count - 1

values.Add(

New CascadingDropDownNameValue(ctable(i).B_NAME, ctable(i).B_NAME))NextReturn values.ToArrayEndFunction

End

Class
I'm having the similar problem. Any new ideas on how to solve it?

There is nothing to do with the number of rows returning from the service. The problem is with your cascadingDropdown declaration.The value for TargetControlID and ParentControlID are given as same, which is causing a recursive call and there by stack overflow.

<ajaxToolKit:cascadingdropdown id="CascadingDropDown1" runat="server"TargetControlID="ddl_GetService" Category="Service" PromptText="Select a Service Code" ServicePath="wsGetServices.asmx" ServiceMethod="GetAllServices"ParentControlID="ddl_GetService" >

-Sajid T.K

No comments:

Post a Comment