Small width layout Medium width layout Maximum width layout Small text Medium text Large text
     Search
Downloads Downloads Directory Directory Forums Forums Forge Forge Blogs Blogs        Marketplace Marketplace Careers Program Careers
Community › Forums Register  |  

telerik -- supercharge your DNN websites
  Ads  
Iron Speed Designer is a software development tool for building database, reporting, and forms applications for .NET without hand-coding.
 


  Sponsors  

Meet Our Sponsors

CrystalTech Web Hosting™
Webhost4life, specialists in DNN hosting
Mad Development is a full service interactive agency focusing on the merge of design, technology, e-commerce, and affiliate marketing by providing total website solutions.
SteadyRain
DataSprings - Great Ideas. Always Flowing.
R2integrated - formerly bi4ce
 


DotNetNuke Forums
 
  Forum  General DotNetN...  Extend It! ( Pr...  AJAX Cascading Drop Downs
Previous Previous
 
Next Next
New Post 7/25/2007 3:02 AM
User is offline Arif Khan
19 posts
10th Ranked


AJAX Cascading Drop Downs 

Can anyone help with implementing the ASP.Net AJAX Cascading Drop Down?

 
New Post 7/29/2007 12:35 AM
User is offline Arif Khan
19 posts
10th Ranked


Re: AJAX Cascading Drop Downs 

My drop downs values are showing a value for "Method error 500". While debugging I realized that the web method in the code behind (GetDropDownContentsPageMethod) is not being invoked by the AJAX CascadingDropDown control. Please can anyone help?

\DesktopModules\Cascading.ASPX:
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
    Category="Make"  PromptText="Please select a make"  LoadingText="[Loading makes...]"
    ServiceMethod="GetDropDownContentsPageMethod" />
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="DropDownList2"
    Category="Model" PromptText="Please select a model" LoadingText="[Loading models...]"
    ServiceMethod="GetDropDownContentsPageMethod" ParentControlID="DropDownList1" />
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="DropDownList3"
    Category="Color" PromptText="Please select a color" LoadingText="[Loading colors...]"
    ServiceMethod="GetDropDownContentsPageMethod"
    ParentControlID="DropDownList2" />

\DesktopModules\Cascading.ASPX.VB:
<WebMethod()> _
<System.Web.Script.Services.ScriptMethod()> _
Public Shared Function GetDropDownContentsPageMethod(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
 Dim cs As New DotNetNuke.Modules.AJAXControlToolkit.CarsService
 Return cs.GetDropDownContents(knownCategoryValues, category)
End Function

App_Code\CarsService.VB:
Imports System
Imports System.Collections.Specialized
Imports System.Web
Imports System.Web.Services
Imports System.Xml
Imports AjaxControlToolkit

Namespace DotNetNuke.Modules.AJAXControlToolkit
    Public Class CarsService
        'Inherits System.Web.Services.WebService

        ' Member variables
        Private _document As XmlDocument
        Private _lock As New Object()

        'we make these public statics just so we can call them from externally for the
        'page method call
        Public ReadOnly Property Document() As XmlDocument
            Get
                If _document Is Nothing Then
                    _document = New XmlDocument()
                    _document.Load(HttpContext.Current.Server.MapPath("CarsService.xml"))
                End If
                Return _document
            End Get
        End Property

        Public ReadOnly Property Hierarchy() As String()
            Get
                Return New String() {"make", "model"}
            End Get
        End Property

        '<summary>
        'Constructor to initialize members
        '</summary>
        Public Sub New()

        End Sub

        '<summary>
        'Helper web service method
        '</summary>
        '<param name="knownCategoryValues">private storage format string</param>
        '<param name="category">category of DropDownList to populate</param>
        '<returns>list of content items</returns>
        <WebMethod()> _
        <System.Web.Script.Services.ScriptMethod()> _
        Public Function GetDropDownContents(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
            'Get a dictionary of known category/value pairs
            Dim knownCategoryValuesDictionary As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

            'Perform a simple query against the data document
            Return CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)
        End Function

    End Class 'WebService
End Namespace

\DesktopModules\CarsService.XML
<?xml version="1.0" encoding="utf-8" ?>
<CarsService>
  <make name="Acura">
    <model name="Integra">
      <color name="Green" />
      <color name="Sea Green" />
      <color name="Pale Green" />
    </model>
    <model name="RL">
      <color name="Red" />
      <color name="Bright Red" />
    </model>
    <model name="TL">
      <color name="Teal" />
      <color name="Dark Teal" />
    </model>
  </make>
  <make name="Audi" value="Audi (value)">
    <model name="A4" value="A4 (value)">
      <color name="Azure" value="Azure (value)" />
      <color name="Light Azure" value="Light Azure (value)" />
      <color name="Dark Azure" value="Dark Azure (value)" />
    </model>
    <model name="S4" value="S4 (value)">
      <color name="Silver" value="Silver (value)" />
      <color name="Metallic" value="Metallic (value)" />
    </model>
    <model name="A6" value="A6 (value)">
      <color name="Cyan" value="Cyan (value)" />
    </model>
  </make>
  <make name="BMW" value="BMW (value)">
    <model name="3 series" value="3 series (value)">
      <color name="Blue" value="Blue (value)" />
      <color name="Sky Blue" value="Sky Blue (value)" />
      <color name="Racing Blue" value="Racing Blue (value)" />
    </model>
    <model name="5 series" value="5 series (value)">
      <color name="Yellow" value="Yellow (value)" />
      <color name="Banana" value="Banana (value)" />
    </model>
    <model name="7 series" value="7 series (value)">
      <color name="Brown" value="Brown (value)" />
    </model>
  </make>
</CarsService>

 

 
New Post 8/1/2007 10:11 PM
User is offline Jon Henning
1622 posts
www.codeendeavors.com
5th Ranked










Re: AJAX Cascading Drop Downs 

Are you talking about in use with DotNetNuke or a separate app?

If inside DNN, then I assume you are using them in a module, which is a usercontrol and not a page.  Therefore PageMethods will not function.  The only real workaround for this is to have the control reference an external webservice (asmx) file instead. 


 
New Post 8/2/2007 1:18 AM
User is offline Arif Khan
19 posts
10th Ranked


Re: AJAX Cascading Drop Downs 

Dear Jon,

I really appreciate the time taken out to reply.

This is indeed for a DNN module. I did try the web service route before but I will try again. At least I know that the "Page Methods" don't work in DNN user modules.

QUESTION:

Do I have to follow this article first:  http://dotnetnuke.adefwebserver.com/DotNetNuke/tabid/195/Default.aspx before I can reference the web service?

thank you

 
New Post 8/6/2007 11:45 PM
User is offline Arif Khan
19 posts
10th Ranked


Re: AJAX Cascading Drop Downs 

I re-used the AjaxWebService module (http://dotnetnuke.adefwebserver.com/DotNetNuke/tabid/195/Default.aspx) with no luck - still get the Method error 500 . The code logistics now looks like this:

CallWebServiceMethods.js

// CallWebServiceMethods.js

// This function calls the Web service method
// passing simple type parameters and the
// callback function 
function Add(a,  b)
{
    YourCompany.Modules.CascadingDropDown.CarService.Add(a, b,
    SucceededCallback);
}

// This function calls the Web service method
// that returns an XmlDocument type. 
function GetXmlDocument()
{
    YourCompany.Modules.CascadingDropDown.CarService.GetXmlDocument(
        SucceededCallbackWithContext, FailedCallback,
        "XmlDocument")
}

// This function calls the Web service method
// passing simple type parameters and the
// callback function 
function GetDropDownContents(a,  b)
{
    YourCompany.Modules.CascadingDropDown.CarService.GetDropDownContents(a, b,
    SucceededCallback, FailedCallback, "XmlDocument");
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName)
{
    var output;
   
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
   
    var readResult;
    if (userContext == "XmlDocument")
 {
 
     if (document.all)
         readResult =
          result.documentElement.firstChild.text;
  else
      // Firefox
     readResult =
          result.documentElement.firstChild.textContent;
  
      RsltElem.innerHTML = "XmlDocument content: " + readResult;
 }
   
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs)
{
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    RsltElem.innerHTML = result;
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
    // Display the error.   
    var RsltElem = document.getElementById("ResultId");
    RsltElem.innerHTML =
    "Service Error: " + error.get_message();
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();


CARSERVICE.ASMX

<%@ WebService Language="VB" Class="YourCompany.Modules.CascadingDropDown.CarService" %>

Imports System.Web
Imports System.Web.Services
Imports System.Xml
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services

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

        ' Member variables
        Private _document As XmlDocument
        Private _lock As New Object()

        'we make these public statics just so we can call them from externally for the
        'page method call
        Public ReadOnly Property Document() As XmlDocument
            Get
                If _document Is Nothing Then
                    _document = New XmlDocument()
                    _document.Load(HttpContext.Current.Server.MapPath("CarsService.xml"))
                End If
                Return _document
            End Get
        End Property

        Public ReadOnly Property Hierarchy() As String()
            Get
                Return New String() {"make", "model"}
            End Get
        End Property
       
        Private _xmlString As String = _
        "<?xml version=""1.0"" encoding=""utf-8"" ?>" + _
        "  <message>" + _
        "    <content>" + _
        "      Welcome to the asynchronous communication layer world!" + _
        "    </content>" + _
        " </message>"
      
        ' This method returns an XmlDocument type.
        <WebMethod()> _
        <ScriptMethod(Responseformat:=Responseformat.Xml)> _
        Public Function GetXmlDocument() As XmlDocument
            Dim xmlDoc As New XmlDocument()
            xmlDoc.LoadXml(_xmlString)
            Return xmlDoc

        End Function 'GetXmlDocument
      
       
        ' This method uses GET instead of POST.
        ' Its input parameters are sent by the
        ' client in the URL query string.
        <WebMethod()> _
        <ScriptMethod(UseHttpGet:=True)> _
        Public Function EchoStringAndDate(ByVal dt As DateTime, _
        ByVal s As String) As String
            Return s + ":" + dt.ToString()
        End Function 'EchoStringAndDate
       
        <WebMethod()> _
        Public Function GetServerTime() As String
       
            Dim serverTime As String = _
            String.format("The current time is {0}.", DateTime.Now)
       
            Return serverTime
   
        End Function 'GetServerTime
    
       
        <WebMethod()> _
        Public Function Add(ByVal a As Integer, _
        ByVal b As Integer) As String
       
            Dim addition As Integer = a + b
            Dim result As String = _
            String.format("The addition result is {0}.", addition.ToString())
       
            Return result
   
        End Function 'Add
       
        <WebMethod()> _
        <ScriptMethod(Responseformat:=Responseformat.Xml, _
            XmlSerializeString:=True)> _
        Public Function GetString() As String
            Return "Hello World"
        End Function
       
        <WebMethod()> _
        <System.Web.Script.Services.ScriptMethod()> _
        Public Function GetDropDownContents(ByVal knownCategoryValues As String, ByVal category As String) As AjaxControlToolkit.CascadingDropDownNameValue()
            'Get a dictionary of known category/value pairs
            Dim knownCategoryValuesDictionary As StringDictionary = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

            'Perform a simple query against the data document
            Return AjaxControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(Document, Hierarchy, knownCategoryValuesDictionary, category)
        End Function
  
    End Class 'WebService
   
End Namespace


CARSERVICE.XML

<?xml version="1.0" encoding="utf-8" ?>
<CarsService>
  <make name="Acura">
    <model name="Integra">
      <color name="Green" />
      <color name="Sea Green" />
      <color name="Pale Green" />
    </model>
    <model name="RL">
      <color name="Red" />
      <color name="Bright Red" />
    </model>
    <model name="TL">
      <color name="Teal" />
      <color name="Dark Teal" />
    </model>
  </make>
  <make name="Audi" value="Audi (value)">
    <model name="A4" value="A4 (value)">
      <color name="Azure" value="Azure (value)" />
      <color name="Light Azure" value="Light Azure (value)" />
      <color name="Dark Azure" value="Dark Azure (value)" />
    </model>
    <model name="S4" value="S4 (value)">
      <color name="Silver" value="Silver (value)" />
      <color name="Metallic" value="Metallic (value)" />
    </model>
    <model name="A6" value="A6 (value)">
      <color name="Cyan" value="Cyan (value)" />
    </model>
  </make>
  <make name="BMW" value="BMW (value)">
    <model name="3 series" value="3 series (value)">
      <color name="Blue" value="Blue (value)" />
      <color name="Sky Blue" value="Sky Blue (value)" />
      <color name="Racing Blue" value="Racing Blue (value)" />
    </model>
    <model name="5 series" value="5 series (value)">
      <color name="Yellow" value="Yellow (value)" />
      <color name="Banana" value="Banana (value)" />
    </model>
    <model name="7 series" value="7 series (value)">
      <color name="Brown" value="Brown (value)" />
    </model>
  </make>
</CarsService>


ViewCascadingDropDown.ascx

<%@ Control language="vb" Inherits="YourCompany.Modules.CascadingDropDown.ViewCascadingDropDown" CodeFile="ViewCascadingDropDown.ascx.vb" AutoEventWireup="true" Explicit="True" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<table>
    <tr>
        <td>Make</td>
        <td><asp:DropDownList ID="DropDownList1" runat="server" Width="170" /></td>
    </tr>
    <tr>
        <td>Model</td>
        <td><asp:DropDownList ID="DropDownList2" runat="server" Width="170" /></td>
    </tr>
    <tr>
        <td>Color</td>
        <td><asp:DropDownList ID="DropDownList3" runat="server" Width="170" AutoPostBack="true"
            OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" /></td>
    </tr>
</table>
        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
            Category="Make"  PromptText="Please select a make"  LoadingText="[Loading makes...]"
            ServiceMethod="GetDropDownContents" />
        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="DropDownList2"
            Category="Model" PromptText="Please select a model" LoadingText="[Loading models...]"
            ServiceMethod="GetDropDownContents" ParentControlID="DropDownList1" />
        <ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="DropDownList3"
            Category="Color" PromptText="Please select a color" LoadingText="[Loading colors...]"
            ServiceMethod="GetDropDownContents"
            ParentControlID="DropDownList2" />    

<br />

<div>
    <h2>
        Calling Web Methods</h2>
    <table>
        <tr align="left">
            <td>
                Method that takes parameters:</td>
            <td>
                <!-- Passing simple parameter types to
                            the Web service. -->
                <button id="Button3" onclick="Add(30, 30); return false;">
                    Add</button>
            </td>
        </tr>
        <tr align="left">
            <td>
                Method that returns XML data:</td>
            <td>
                <!-- Get Xml. -->
                <button id="Button4" onclick="GetXmlDocument(); return false;">
                    Get Xml</button>
            </td>
        </tr>
        <tr align="left">
            <td>
                Method that returns XML data:</td>
            <td>
                <!-- Get Xml. -->
                <button id="Button1" onclick="GetDropDownContents('','Make'); return false;">
                    Get Xml</button>
            </td>
        </tr>                           
    </table>
</div>
<hr />
<div>
    <span id="ResultId"></span>
</div>

 


ViewCascadingDropDown.ascx.VB


'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2006
' by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
'
Imports DotNetNuke
Imports DotNetNuke.Security.Roles
Imports System.Collections.Generic
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Security
Imports DotNetNuke.Services.Exceptions
Imports System.Web

Namespace YourCompany.Modules.CascadingDropDown

    ''' -----------------------------------------------------------------------------
    ''' <summary>
    ''' The ViewDynamicModule class displays the content
    ''' </summary>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    ''' </history>
    ''' -----------------------------------------------------------------------------
    Partial Class ViewCascadingDropDown
        Inherits DotNetNuke.Entities.Modules.PortalModuleBase

#Region "Private Members"

        Private strTemplate As String

#End Region

#Region "Event Handlers"

        ''' -----------------------------------------------------------------------------
        ''' <summary>
        ''' Page_Load runs when the control is loaded
        ''' </summary>
        ''' <remarks>
        ''' </remarks>
        ''' <history>
        ''' </history>
        ''' -----------------------------------------------------------------------------
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                If Not Page.IsPostBack Then
                    ' Determine if AJAX is installed
                    If DotNetNuke.Framework.AJAX.IsInstalled Then
                        DotNetNuke.Framework.AJAX.RegisterScriptManager()
                        ' Create a reference to the Script Manager
                        Dim objScriptManager As ScriptManager = ScriptManager.GetCurrent(Me.Page)
                        ' Add a reference to the web service
                        Dim objServiceReference As ServiceReference = New ServiceReference
                        objServiceReference.Path = "~/DesktopModules/CascadingDropDown/CarService.asmx"
                        objScriptManager.Services.Add(objServiceReference)
                        Dim objScriptReference As ScriptReference = New ScriptReference
                        objScriptReference.Path = "~/DesktopModules/CascadingDropDown/CallWebServiceMethods.js"
                        objScriptManager.Scripts.Add(objScriptReference)
                    End If
                End If
            Catch exc As Exception        'Module failed to load
                ProcessModuleLoadException(Me, exc)
            End Try
        End Sub

#End Region


    End Class

End Namespace

 
Previous Previous
 
Next Next
  Forum  General DotNetN...  Extend It! ( Pr...  AJAX Cascading Drop Downs
 


Forum Policy

These Discussion Forums are dedicated to the discussion of the DotNetNuke Web Application Framework.

For the benefit of the community and to protect the integrity of the project, please observe the following posting guidelines:

1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DotNetNuke.
2. Discussion or promotion of DotNetNuke product releases under a different brand name are strictly prohibited.
3. No Flaming or Trolling.
4. No Profanity, Racism, or Prejudice.
5. Site Moderators have the final word on approving/removing a thread or post or comment.
6. English language posting only, please.

 


Alki Homes - Seattle, WA
Exemplary service for your Seattle Real Estate needs. It's what you deserve from your Realtor®!
www.alkihomes.com
PointClick DotNetNuke Solutions
PointClick Technologies provides high-end DNN Hosting for businesses.
PointClick.Net Hosted Solutions
Active Modules, Inc.
Creators of Active Forums, the best forum module for DotNetNuke
www.activemodules.com

DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke®, DNN®, and the DotNetNuke logo are trademarks of DotNetNuke Corporation
Hosted by MaximumASP