CascadingDropDown and Wizard Control

Last post 02-12-2007 9:13 PM by David Anson. 13 replies.

Sort Posts:

  • CascadingDropDown and Wizard Control

    01-25-2007, 6:24 PM
    • Loading...
    • rojasc
    • Joined on 01-25-2007, 6:31 PM
    • Posts 10

    Hello, i'm using a wizard control to register data and in wizard steps i'm using dropdownlist controls with CascadingDropDown. when i work in a new record all is fine, but when i try update a record i found this trouble.

    in the  Sub Page_Load i have a source like this:

     

    if not Page.ispostback then
        dim rs as new recordset
        ...     'filling recordset 

        ' this work fine because the CascadingDropDown1 and DropDownList1 is in the first wizard step
        me.CascadingDropDown1.SelectedValue=rs.tables(0).rows(0)("SomeColumn1")


        'this NOT work because the CascadingDropDown2 and DropDownList2 is in the second wizard step
        me.CascadingDropDown2.SelectedValue=rs.tables(0).rows(0)("SomeColumn2")


        'with simple text control i don't have any trouble
       me.text1.text="SomeWords"  'it is in the first wizard step
       me.text2.text="xx  yy  zz" 'it work fine and is in the secod wizard step.
    end

     

    what magical code i need to write in the code-behind to make CascadingDropDown2 work fine??? Tongue Tied

    i tried to put the value with javascript page onLoad,  with vb putting directly the value to dropdownd2, but nothing work.

    Saludos desde Lima Perú
    Carlos Rojas

  • Re: CascadingDropDown and Wizard Control

    01-26-2007, 3:23 PM

    Maybe move the Xxx2 stuff out of the .isPostBack check and make sure you only do it during the proper wizard step?

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: CascadingDropDown and Wizard Control

    01-26-2007, 6:33 PM
    • Loading...
    • rojasc
    • Joined on 01-25-2007, 6:31 PM
    • Posts 10
    yes,i did it, and this show me the record, but only show ,when i try to get data with :

    DropDown2.SelectedItem.Text

    it show "undefined"

    and i have to change manually the selected item in internet explorer to another item and then return to the previous item to get the rigth item when i use:

    DropDown2.SelectedItem.Text

     

  • Re: CascadingDropDown and Wizard Control

    01-26-2007, 6:35 PM
    Please reply with a complete, simple, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: CascadingDropDown and Wizard Control

    01-26-2007, 7:30 PM
    • Loading...
    • rahul_2111
    • Joined on 08-22-2006, 9:43 AM
    • India
    • Posts 3

    Is there a possibility that CascadingDropdown can be used without the use of web-services?

     Thank you for an early reply.

    rahul.2111@gmail.com

    Rahul
  • Re: CascadingDropDown and Wizard Control

    01-26-2007, 10:53 PM
    • Loading...
    • rojasc
    • Joined on 01-25-2007, 6:31 PM
    • Posts 10

    Ok, this is the code, i'm using Pubs Data Base, in Page_Load event i fill a dataset with a record from employee, then set the job_id in CascadingDropDown_Job.SelectedValue, when i load step 2 set  pub_id in CascadingDropDown_publisher.SelectedValue,then  in step 1 and 2 i read the TEXT selected, but in step 3 i can't obtain the rigth DropDownList_Job.SelectedItem.Text and DropDownList_publisher.SelectedItem.Text, if i back to step 1 o 2 and select another item in de dropdownlist , when i return to step 3 now i read the rigth DropDownList_Job.SelectedItem.Text and DropDownList_publisher.SelectedItem.Text.

     

    MyPage.aspx:

    <%@ Page Language="VB"  EnableEventValidation="false" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            If Not Page.IsPostBack Then
                Dim Connection As New SqlConnection("Data Source=localhost;Initial Catalog=Pubs;Integrated Security=True")
                Connection.Open()
                Dim Command As New SqlCommand("select * from employee where emp_id='PMA42628M'", Connection)
                Dim DataAdapter As New SqlDataAdapter(Command)
                Dim DataSet As New Data.DataSet
                DataAdapter.Fill(DataSet)
                Me.CascadingDropDown_Job.SelectedValue = DataSet.Tables(0).Rows(0)("job_id")
                
                'this line don't work, but i hope work in future release 
                'Me.CascadingDropDown_publisher.SelectedValue = DataSet.Tables(0).Rows(0)("pub_id")
            End If
            Page.DataBind()
        End Sub
    
        Protected Sub Wizard1_ActiveStepChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            Select Case Wizard1.ActiveStepIndex
                Case 1
                    If Me.PostBack_Step2.Value = "0" Then
                        Dim Connection As New SqlConnection("Data Source=localhost;Initial Catalog=Pubs;Integrated Security=True")
                        Connection.Open()
                        Dim Command As New SqlCommand("select * from employee where emp_id='PMA42628M'", Connection)
                        Dim DataAdapter As New SqlDataAdapter(Command)
                        Dim DataSet As New Data.DataSet
                        DataAdapter.Fill(DataSet)
                        
                        'this line work fine
                        Me.CascadingDropDown_publisher.SelectedValue = DataSet.Tables(0).Rows(0)("pub_id")
                        '-------------------------
                        
                        Me.PostBack_Step2.Value = "1"
                    Else
                        'ActiveStepChanged code
                    End If
                Case 2
                    If Me.PostBack_Step3.Value = "0" Then
                        'postback step3
                        Me.PostBack_Step3.Value = "1"
                    Else
                        'ActiveStepChanged
                    End If
            End Select
        End Sub
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Página sin título</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Wizard ID="Wizard1" 
                runat="server" ActiveStepIndex="0" BackColor="#FFFBD6" BorderColor="#FFDFAD"
                BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" Height="232px" 
                Width="456px" OnActiveStepChanged="Wizard1_ActiveStepChanged">
                <SideBarStyle BackColor="#990000" Font-Size="0.9em" VerticalAlign="Top" />
                <NavigationButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid"
                    BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" />
                <WizardSteps>
                    <asp:WizardStep runat="server" StepType="Start" Title="Step 1">
                        <asp:DropDownList ID="DropDownList_Job" runat="server">
                        </asp:DropDownList>
                        <br />
                        <br />
                        <cc1:CascadingDropDown ID="CascadingDropDown_Job" runat="server" BehaviorID="Wizard1_CascadingDropDown1"
                            Enabled="True" TargetControlID="DropDownList_Job" ServiceMethod="Jobs" ServicePath="MyWebService.asmx" LoadingText="Loading..." PromptText="Select" Category="Job">
                        </cc1:CascadingDropDown>
                    </asp:WizardStep>
                    <asp:WizardStep runat="server" StepType="Step" Title="Step 2">
                        &nbsp;
                        <asp:DropDownList ID="DropDownList_publisher" runat="server">
                        </asp:DropDownList>
                        <cc1:CascadingDropDown ID="CascadingDropDown_publisher" runat="server" BehaviorID="Wizard1_CascadingDropDown_publisher"
                            Category="Publisher" Enabled="True" LoadingText="Loading..." PromptText="Select"
                            ServiceMethod="Publishers" ServicePath="MyWebService.asmx" TargetControlID="DropDownList_publisher">
                        </cc1:CascadingDropDown>
                    </asp:WizardStep>
                    <asp:WizardStep runat="server" StepType="Finish" Title="Step 3">
                        Job :
                        <asp:Label ID="Label1" runat="server" Text='<%# DropDownList_Job.SelectedItem.Text %>'></asp:Label>
                        <br />
                        CascadingDropDown_Job:
                        <asp:Label ID="Label3" runat="server" Text='<%# CascadingDropDown_Job.SelectedValue %>'></asp:Label>
                        <br />
                        <br />
                        Publisher:
                        <asp:Label ID="Label2" runat="server" Text='<%# DropDownList_publisher.SelectedItem.Text %>'></asp:Label>
                        <br />
                        CascadingDropDown_publisher:
                        <asp:Label ID="Label4" runat="server" Text='<%# CascadingDropDown_publisher.SelectedValue %>'></asp:Label>
                    </asp:WizardStep>
                </WizardSteps>
                <SideBarButtonStyle ForeColor="White" />
                <HeaderStyle BackColor="#FFCC66" BorderColor="#FFFBD6" BorderStyle="Solid" BorderWidth="2px"
                    Font-Bold="True" Font-Size="0.9em" ForeColor="#333333" HorizontalAlign="Center" />
            </asp:Wizard>
            <br />
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:HiddenField ID="PostBack_Step2" runat="server" Value="0" />
        
        </div>
            <asp:HiddenField ID="PostBack_Step3" runat="server" />
        </form>
    </body>
    </html>
    

     

    MyWebService.asmx:

    <%@ WebService Language="VB" Class="MyWebService"   %>
    
    Imports System.Web
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Data.SqlClient
    Imports System.Data
    Imports AjaxControlToolkit
    Imports System.Collections.Generic
    
    
    <WebService(Namespace:="http://tempuri.org/")> _
    <Web.Script.Services.ScriptService()> _
    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class MyWebService
        Inherits System.Web.Services.WebService
        <WebMethod()> _
        Public Function Jobs(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
            Dim Connection As New SqlConnection("Data Source=localhost;Initial Catalog=Pubs;Integrated Security=True")
            Connection.Open()
            Dim Command As New SqlCommand("select job_desc, job_id from jobs", Connection)
            Dim DataAdapter As New SqlDataAdapter(Command)
            Dim DataSet As New Data.DataSet
            DataAdapter.Fill(DataSet)
            Dim Result As New List(Of CascadingDropDownNameValue)
            For Each row As DataRow In DataSet.Tables(0).Rows
                Result.Add(New CascadingDropDownNameValue(row("job_desc"), CStr(row("job_id"))))
            Next
            Return Result.ToArray()
        End Function
        
        <WebMethod()> _
        Public Function Publishers(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
            Dim Connection As New SqlConnection("Data Source=localhost;Initial Catalog=Pubs;Integrated Security=True")
            Connection.Open()
            Dim Command As New SqlCommand("select pub_name, pub_id from publishers ", Connection)
            Dim DataAdapter As New SqlDataAdapter(Command)
            Dim DataSet As New Data.DataSet
            DataAdapter.Fill(DataSet)
            Dim Result As New List(Of CascadingDropDownNameValue)
            For Each row As DataRow In DataSet.Tables(0).Rows
                Result.Add(New CascadingDropDownNameValue(row("pub_name"), CStr(row("pub_id"))))
            Next
            Return Result.ToArray()
        End Function
    
        
        
        
    End Class
    
     
  • Re: CascadingDropDown and Wizard Control

    01-29-2007, 12:42 PM
    • Loading...
    • rojasc
    • Joined on 01-25-2007, 6:31 PM
    • Posts 10

    at the end in this post http://forums.asp.net/thread/1538386.aspx dhaligas has the same trouble, anybody has a fix to this bug???

  • Re: CascadingDropDown and Wizard Control

    01-29-2007, 6:06 PM
    • Loading...
    • rojasc
    • Joined on 01-25-2007, 6:31 PM
    • Posts 10

    a tip, if you write :

    MyCascadeDropDown.SelectedValue="1:::SomeText"

    the result is

    MyDropDown.Selected=1

    MyDropDown.SelectedItem.Text="SomeText"

    with this tip dissaper the 'undefined', but you have to write a code that obtain the text

  • Re: CascadingDropDown and Wizard Control

    01-30-2007, 12:00 AM
    • Loading...
    • rojasc
    • Joined on 01-25-2007, 6:31 PM
    • Posts 10

    well i have to fix it my self, i will post the solution when finish the test

     

  • Re: CascadingDropDown and Wizard Control

    01-30-2007, 9:41 AM
    • Loading...
    • dhaligas
    • Joined on 12-01-2006, 6:19 AM
    • Posts 4

    The fix I used to get the SelectedItem.Text value from the cascading drop down requires you to edit the CascadingDropDownBehavior.js file. 

    I updated the set_SelectedValue property so that it always gets set.  The lines I changed are commented out.   This will always return the SelectedText and Value.

     

    set_SelectedValue :

    function(value, text) {

    //if (this._selectedValue != value) {

    if (!text) {

    // Initial population by server; look for "value:::text" pair

    var i = value.indexOf(':::');

    if (-1 != i) {

    text = value.slice(i + 3);

    value = value.slice(0, i);

    }

    }

    this._selectedValue = value;

    AjaxControlToolkit.CascadingDropDownBehavior.callBaseMethod(

    this, 'set_ClientState', [ this._selectedValue+':::'+text ]);

    this.raisePropertyChanged('SelectedValue');

    //}

    },

     

  • Re: CascadingDropDown and Wizard Control

    01-30-2007, 12:30 PM
    • Loading...
    • rojasc
    • Joined on 01-25-2007, 6:31 PM
    • Posts 10

    good, i fix it with this:

        // Member variables
        this._parentElement = null;
        this._changeHandler = null;
        this._parentChangeHandler = null;
        
        this._lastParentValues = null;
        this._selectedValue = null;
        
        //added by rojasc
        this._selectedText= null;

     and

        set_SelectedValue : function(value, text) {
            if (this._selectedValue != value) {
            // this run when the value change
                if (!text) {
                    // Initial population by server; look for "value:::text" pair
                    var i = value.indexOf(':::');
                    if (-1 != i) {
                        text = value.slice(i + 3);
                        value = value.slice(0, i);
                    }
                }
                this._selectedValue = value;
                //added by Rojasc
                this._selectedText = text;
                AjaxControlToolkit.CascadingDropDownBehavior.callBaseMethod(this, 'set_ClientState', [ this._selectedValue+':::'+text ]);
                this.raisePropertyChanged('SelectedValue');
           
             }else{
                // this run when the text change
                if(this._selectedText!=text){
                    this._selectedText = text;
                    AjaxControlToolkit.CascadingDropDownBehavior.callBaseMethod(this, 'set_ClientState', [ this._selectedValue+':::'+text ]);
                    this.raisePropertyChanged('SelectedValue');
                }else{
                // put here anything that want to run when nothing change
                }
            //--------------------------------------------
            }
        },
    

     

    I think that your and my fixs are little service pack for Ajax  Toolkit

     

     

  • Re: CascadingDropDown and Wizard Control

    01-30-2007, 6:16 PM
    It seems like you are onto something here, but I'd like to understand the issue better first. Could you please update the sample above so that it doesn't have any SQL dependencies and it will run and demonstrate the problem when added to the SampleWebSite? (Feel free to use the existing web service.) A simple sample that demonstrates the problem combined with the proposed fixes above would go a long way to fixing this in the Toolkit. Thanks!
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: CascadingDropDown and Wizard Control

    01-30-2007, 11:35 PM
    • Loading...
    • rojasc
    • Joined on 01-25-2007, 6:31 PM
    • Posts 10

    the trouble is in javascript, not in sql server.

    this the most simple example:

    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" EnableEventValidation="false" %>

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

    <!

    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" />

    <div>

    <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" Category="MyCategory"

    LoadingText="wait..." PromptText="select" ServiceMethod="MyMethod" TargetControlID="DropDownList1" ServicePath="MyWebService.asmx">

    </cc1:CascadingDropDown>

    </div>

    <asp:DropDownList ID="DropDownList1" runat="server">