p_love
asked on
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.IsInAsyn cPostBack Then
Call Bind_Filters()
End If
End Sub
Private Sub Bind_Filters()
' Bind all the filters
Call Bind_DropDown("SP_DUNDAS_L UT_01", Me.ddSubstance, "Substance", False, "@TA", "Oncology/Infection")
Call Bind_DropDown("SP_DUNDAS_L UT_02", Me.ddProject, "Project", True, "@SUBSTANCE", "(All)")
Call Bind_DropDown("SP_DUNDAS_L UT_03", Me.ddActivity, "Activity", True, "@PROJECT", "(All)")
Call Bind_DropDown("SP_DUNDAS_L UT_04", Me.ddRegion, "Region", False)
Call Bind_DropDown("SP_DUNDAS_L UT_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.DataP arameter
Dim factory As MISF.MISFDataAbstractFacto ry
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.StoredProcedur e
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.UserR ole.Writer
.Transactional = False
End With
ds = factory.ExecuteDataSet(req uest)
dsFinal = ds.ReturnedDataSet
dd.Items.Clear()
dr = dsFinal.Tables(0).CreateDa taReader
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_SelectedIndexC hanged(ByV al sender As Object, ByVal e As System.EventArgs) Handles ddSubstance.SelectedIndexC hanged
Dim strValue As String
If ScriptManager1.IsInAsyncPo stBack Then
strValue = ddSubstance.SelectedItem.V alue
If strValue = "(All)" Then
Call Bind_DropDown("SP_DUNDAS_L UT_02", Me.ddProject, "Project", True)
Call Bind_DropDown("SP_DUNDAS_L UT_03", Me.ddActivity, "Activity", True)
Else
Call Bind_DropDown("SP_DUNDAS_L UT_02", Me.ddProject, "Project", False, "@SUBSTANCE", strValue)
Call Bind_DropDown("SP_DUNDAS_L UT_03", Me.ddActivity, "Activity", False, "@PROJECT", ddProject.SelectedItem.Val ue)
End If
End If
End Sub
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.IsInAsyn
Call Bind_Filters()
End If
End Sub
Private Sub Bind_Filters()
' Bind all the filters
Call Bind_DropDown("SP_DUNDAS_L
Call Bind_DropDown("SP_DUNDAS_L
Call Bind_DropDown("SP_DUNDAS_L
Call Bind_DropDown("SP_DUNDAS_L
Call Bind_DropDown("SP_DUNDAS_L
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.DataP
Dim factory As MISF.MISFDataAbstractFacto
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.StoredProcedur
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.UserR
.Transactional = False
End With
ds = factory.ExecuteDataSet(req
dsFinal = ds.ReturnedDataSet
dd.Items.Clear()
dr = dsFinal.Tables(0).CreateDa
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_SelectedIndexC
Dim strValue As String
If ScriptManager1.IsInAsyncPo
strValue = ddSubstance.SelectedItem.V
If strValue = "(All)" Then
Call Bind_DropDown("SP_DUNDAS_L
Call Bind_DropDown("SP_DUNDAS_L
Else
Call Bind_DropDown("SP_DUNDAS_L
Call Bind_DropDown("SP_DUNDAS_L
End If
End If
End Sub
ASKER
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
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
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.
This would be my first recomendaton.
ASKER
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
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
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....
I'm wondering if the page-level databind is pulling from viewstate....
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
>>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?
ASKER
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_SelectedInde xChanged(B yVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedInde xChanged
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
Simple example:
Protected Sub DropDownList1_SelectedInde
If DropDownList1.SelectedItem
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
ASKER
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
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
ASKER
...its almost as if the part of the asynchronous postback that returns the updated html isnt happening?
ASKER
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_L UT_02", Me.ddProject, "Project", False, "@SUBSTANCE", strValue)
Call Bind_DropDown("SP_DUNDAS_L UT_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
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_L
Call Bind_DropDown("SP_DUNDAS_L
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
point taken
thx
thx
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx