none
CascadingDropDown Question

    Question

  • In the AjaxControlToolkit sample website, there is an example that uses the CascadingDropDown control.  In that example, two of the three dropdowns make calls to a WebService via the ServicePath/ServiceMethod properties of the CascadingDropDown control.

    However, one of the dropdowns calls the WebService via a ServiceMethod property which points to a function on the page itself  (i.e. ServicePath = "").  This function creates a new  WebService object, and calls the needed function.

    This works great in the sample website, but not when I attempt to do this on my website.

    For some reason, the CascadingDropDowns on my page do not recognize that I have function on my page that needs to be called instead of the remote WebService call.  Consequently, when my page loads, I get a JSCript error, and the dropdowns do not populate.

    My page function is "decorated" with the <WebMethod()> <System.Web.Script.Services.ScriptMethod()> tags (I'm using VB.NET).  I don't know what I need to do to get Ajax to recognize that the page function exists, and to call it.

    If you need more details, here they are:

    This is my test page (you'll notice that CascadingDropDown2 has no ServicePath property):

     

    <%@ Page Language="vb" AutoEventWireup="true" CodeBehind="TestPage.aspx.vb" Inherits="TLLeadManagerOnline.TestPage" EnableEventValidation="false" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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 EnablePartialRendering="true" ID="ScriptManager1" runat="server"></asp:ScriptManager>

    <div>

    &nbsp;<asp:Panel ID="Panel1" runat="server" Height="72px" Width="304px">

    <asp:DropDownList ID="DropDownList1" runat="server" Width="304px" Enabled=true>

    </asp:DropDownList>

    <asp:DropDownList ID="DropDownList2" runat="server" Width="304px">

    </asp:DropDownList>

    <asp:DropDownList ID="DropDownList3" runat="server" Width="304px">

    </asp:DropDownList></asp:Panel>

    </div>

    &nbsp;&nbsp;

    <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="CID" PromptText="Select an Insurance Company"

    ServiceMethod="GetInsCompanies" LoadingText="[Loading companies...]" TargetControlID="DropDownList1" ServicePath="PolicyDropDowns.asmx">

    </cc1:CascadingDropDown>

    <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" Category="TID" ParentControlID="DropDownList1"

    PromptText="Select a Policy Type" ServiceMethod="GetPolicyTypesP" TargetControlID="DropDownList2">

    </cc1:CascadingDropDown>

    <cc1:CascadingDropDown ID="CascadingDropDown3" runat="server" Category="NID" ParentControlID="DropDownList2"

    PromptText="Select a Policy Name" ServiceMethod="GetPolicyNames" ServicePath="PolicyDropDowns.asmx"

    TargetControlID="DropDownList3">

    </cc1:CascadingDropDown>

    </form>

    </body>

    </html>

     

    Here is the "Code Behind" the test page:

     

    Imports System

    Imports System.Web.Services

    Imports AjaxControlToolkit

     

    Partial Public Class TestPage

    Inherits System.Web.UI.Page

     

    <WebMethod()> <System.Web.Script.Services.ScriptMethod()> _

    Public Function GetPolicyTypesP(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()

    Return New PolicyDropDowns().GetPolicyTypes(knownCategoryValues, category)

    End Function

    End Class

     

    All of this is exactly analogous to the the CascadingDropDown example on the AjaxControlToolkit sample website, except it works there, and not here.  That is to say, the function above, GetPolicyTypesP, is never called.

     

    I have tried almost everything to get this to work.  The only thing I haven't tried is the solution that works. 

     

    Can anyone help?

     

    TIA

     

    James

    Friday, August 10, 2007 7:02 PM

All replies

  • Hi James,

     

    I was wondering if you figured anything out on this?  I'm having the exact same problem (I have been trying to use the AJAX training video).

     

    One thing I figured out is that this problem only seems to happen on web projects, but not web sites.  It seems like we have to somehow declare the web method on the page, but I have not been able to figure out how.

     

    Since we only need to access the method this way if we are using page methods, I've tried to set up my program by simply calling the web method (like drop downs 1 and 3 do).  That took care of the runtime problem.  However, now when I run my application the drop down lists appear, but the only choice is '[Method error 500]'.  I've been posting on the ASP.net forums but so far no luck.

     

    I've tried to trace my program, and it appears that the web method is never getting called, which I think is what is generating the method error 500.  I put a trace in the AJAX sample application, and I can step through the web method as it executes.

     

    If you or anyone else has a solution for this, it would be most appreciated.

     

    Thanks!

     

    Thursday, August 16, 2007 12:55 PM
  • Hello,

     

    I'm having the same problem!  did you manage to solve this.

     

    cheers

     

     

    Thursday, August 23, 2007 10:03 AM
  • I did solve this.  Actually, I found two ways of accomplishing what I wanted to do, which was to make a session variable available to a webservice method.

     

    But first, I found that in order to get the DropDowns to recogonized a page method, you need to declare it as Shared.

     

    So, my method declaration should look like this:

     

    <WebMethod()> _

    Public Shared Function GetPolicyTypesP(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()

    Return New PolicyDropDowns().GetPolicyTypes(knownCategoryValues, category)

    End Function

     

    That's all it took.

     

    The other way I found to do what I needed to do is something else you might find useful.  The reason I wanted to do this in the first place was so I could use a constructor on the New statement above in order to send a Session variable to the Webservice (a database connection string), like this:

    <WebMethod()> _

    Public Shared Function GetPolicyTypesP(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()

    Return New PolicyDropDowns(Session("ConnectString")).GetPolicyTypes(knownCategoryValues, category)

    End Function

     

    But, this is unneccessary.  In the Web Method decalrations in the Webservice .asmx file, adding the

    EnableSession:=True parameter gives access to my session variables to the webservice.  That is:

     

    <WebMethod(EnableSession:=True)> Public Function

    Thursday, August 23, 2007 5:33 PM