• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2678
  • Last Modified:

Cascading DropDown not working in or out of UpdatePanel

Hello,

I am trying to do something really simple.  I am trying to capture the SelectedIndexChanged event in one dropdown, use the value as a parameter to fire a stored procedure - and then populate a second drop down with the values.

It doesnt work.  When I step through the code, I see that the DataReader is returning records, and appears to be going through the process of adding items to the drop down..only the original entry from the inital page load is in the drop down in the browser.

I have eveything in an UpdatePanel, but it doesnt work in or out of the UpdatePanel.  I have reverted to the DataReader.Read method as a last resort....because the DataBind method wasnt working either.

Surely this is bread and butter stuff!?

Regards

p_love





    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' First we need to populate the drop down lists
        If Not Page.IsPostBack And Not Me.ScriptManager1.IsInAsyncPostBack Then
            Call Bind_Filters()
        End If

    End Sub




    Private Sub Bind_Filters()
        ' Bind all the filters
        Call Bind_DropDown("SP_DUNDAS_LUT_01", Me.ddSubstance, "Substance", False, "@TA", "Oncology/Infection")
        Call Bind_DropDown("SP_DUNDAS_LUT_02", Me.ddProject, "Project", True, "@SUBSTANCE", "(All)")
        Call Bind_DropDown("SP_DUNDAS_LUT_03", Me.ddActivity, "Activity", True, "@PROJECT", "(All)")
        Call Bind_DropDown("SP_DUNDAS_LUT_04", Me.ddRegion, "Region", False)
        Call Bind_DropDown("SP_DUNDAS_LUT_05", Me.ddSite, "Site", True, "@REGION", "(All)")


    End Sub


    Private Sub Bind_DropDown(ByVal strCommand As String, ByVal dd As DropDownList, ByVal strDataTextField As String, ByVal blnInitialise As Boolean, Optional ByVal strParamName As String = Nothing, Optional ByVal strParam As String = Nothing)

        Dim request As New MISF.MISFDataRequest
        Dim param As New MISF.MISFDataRequest.DataParameter
        Dim factory As MISF.MISFDataAbstractFactory
        Dim ds As MISF.MISFDataSet
        Dim dsFinal As New DataSet
        Dim dr As IDataReader


        If blnInitialise = False Then
            factory = New MISF.MISFSqlFactory

            With request
                .Command = strCommand
                .CommandType = CommandType.StoredProcedure

                If Not (strParam Is Nothing) And Not (strParamName Is Nothing) Then
                    ' We only need to add parameters to the collection if we have any!
                    param.ParamName = strParamName
                    param.ParamValue = strParam

                    .Parameters.Add(param)
                End If

                .Role = MISF.MISFDataRequest.UserRole.Writer

                .Transactional = False

            End With

            ds = factory.ExecuteDataSet(request)

            dsFinal = ds.ReturnedDataSet

            dd.Items.Clear()

            dr = dsFinal.Tables(0).CreateDataReader

            While dr.Read
                dd.Items.Add(dr.Item(0))
            End While



        ElseIf blnInitialise = True Then
            ' This is a first pass initialisation and so we only need to add "(All)"
            dd.Items.Add("(All)")
        End If

        Page.DataBind()

    End Sub





    Protected Sub ddSubstance_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddSubstance.SelectedIndexChanged
        Dim strValue As String

        If ScriptManager1.IsInAsyncPostBack Then
            strValue = ddSubstance.SelectedItem.Value
            If strValue = "(All)" Then
                Call Bind_DropDown("SP_DUNDAS_LUT_02", Me.ddProject, "Project", True)
                Call Bind_DropDown("SP_DUNDAS_LUT_03", Me.ddActivity, "Activity", True)
            Else
                Call Bind_DropDown("SP_DUNDAS_LUT_02", Me.ddProject, "Project", False, "@SUBSTANCE", strValue)
                Call Bind_DropDown("SP_DUNDAS_LUT_03", Me.ddActivity, "Activity", False, "@PROJECT", ddProject.SelectedItem.Value)

            End If
        End If


    End Sub
0
p_love
Asked:
p_love
  • 8
  • 3
  • 3
2 Solutions
 
McExpCommented:
THere is an ajax component that might be perfect for your requirements: -

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx
0
 
p_loveAuthor Commented:
Hi,

Thanks.  I am aware of this control.  The issue I have is that some dropdowns need to cascade and some don't (some have fixed content and are not part of any hierarchy).

I need to understand why this isnt working as it is.

Regards

p_love
0
 
McExpCommented:
ok, the easiest way I have found to impliment UpdatePanel stuff is first to get it working without ajax and standard postbacks, then all you need do is wrap it up with the Update Panel and all is ok.

This would be my first recomendaton.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
p_loveAuthor Commented:
OK,

Thanks.  Out of the UpdatePanel it works fine.  I thought the beaty of the UpdatePanel was you just wrapped your controls around it and off you go.

Any ideas?

p_love
0
 
samtran0331Commented:
what happens if you take out "Page.Databind()" from your Bind_DropDown function?
I'm wondering if the page-level databind is pulling from viewstate....
0
 
p_loveAuthor Commented:
Hi,

I have tried removing both databinds (do I need to databind if I am iterating with the reader?  I dont think so so I removed it).  No joy.  I have added the dd.DataBind() back in and got rid of the  Page.DataBind(), no joy.

I have just tried adding one of the dropdowns as a specific UpdatePanel trigger...no joy.  

I have tried all the above with a Conditional / Always UpdateMode option for the UpdatePanel...no joy!

Regards

p_love
0
 
McExpCommented:
Odd, I have never had any trouble taking conventional Postbacks and wrapping them entirely in a UpdatePanel then it just works.
0
 
samtran0331Commented:
So in your original post, you said:
>>I have eveything in an UpdatePanel, but it doesnt work in or out of the UpdatePanel.

But at postID:20066304, you said it works when it *is* outside of the UpdatePanel?

And when you first hit the page, Bind_Filters runs correctly?
0
 
p_loveAuthor Commented:
I just created a simple example in a new page and it works Async.  Must be something to do with my code..or with the fact a database access is occurring.

Simple example:

  Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        If DropDownList1.SelectedItem.Value = 1 Then
            DropDownList2.Items.Clear()
            DropDownList2.Items.Add(1)
            DropDownList2.Items.Add(2)
            DropDownList2.Items.Add(3)
            DropDownList2.Items.Add(4)
        Else
            DropDownList2.Items.Clear()
            DropDownList2.Items.Add(10)
            DropDownList2.Items.Add(11)
            DropDownList2.Items.Add(12)
            DropDownList2.Items.Add(13)

        End If
0
 
p_loveAuthor Commented:
Hi,

Yes...I made a mistake in my original post.  It does work outside of the UpdatePanel perfectly.

In the UpdatePanel, I can put a breakpoint on the async postback, and it walks through - adding items (apparently) from the datareader to the combo box....Just nothing is displayed in the Browser.

Regards

p_love
0
 
p_loveAuthor Commented:
...its almost as if the part of the asynchronous postback that returns the updated html isnt happening?
0
 
p_loveAuthor Commented:
DOOOHHHHHHH!

I put some javascript in to trace the events of the PageRequestManager to trace what was happening.  It appears that the second item here is quite a long query and so the ScriptManager was timing out before the data results were returned!!

When I remmed out the second line, all worked as expected.

 Call Bind_DropDown("SP_DUNDAS_LUT_02", Me.ddProject, "Project", False, "@SUBSTANCE", strValue)
Call Bind_DropDown("SP_DUNDAS_LUT_03", Me.ddActivity, "Activity", False, "@PROJECT",

If I had put an update progress panel on, I guess I would have seen it.  

Is there any way to disable controls on an async postback?  What confused me was the fact I could still access all the dropdowns and though the postback had finished?

Regards

p_love
0
 
samtran0331Commented:
>>I could still access all the dropdowns and though the postback had finished?
Well without AJAX, the page appears "locked" because the entire page is still rendering...the whole point of AJAX is to keep the page "unlocked" (and keep control access available) while only parts get rendered (in this case the listitems of the dropdownlist, not the dropdownlist itself...

does ddActivity need to get populated at the same time?
why not just use the progress panel instead of disabling the control?
0
 
p_loveAuthor Commented:
point taken

thx
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 8
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now