Showing posts with label onselectedindexchanged. Show all posts
Showing posts with label onselectedindexchanged. Show all posts

Monday, March 26, 2012

CascadingDropDowns cant fire OnSelectedIndexChanged client events?

Greetings, all...

I've got a page with a CascadingDropDown setup. On the third dropdown, I want to fire an update panel event to fetch data.

For whatever reason, it does not appear that I can get any of the three dropdowns in the cascade to recognize a client-side OnSelectedIndexChanged event - even when added programmatically in the code file.

The event/action are emitted correctly to the control, but it doesn't seem to fire the event.

I've been trying to find the answer in previous posts and Google, but I don't seem to be finding the answers anywhere. I'm hoping there's someone out in forumland that has seen this before and knows how to resolve the issue.

Thanks in advance for the help,

Ric Castagna

Unless I'm mistaken, OnSelectedIndexChanged is a server-side event, not a client-side one.

Saturday, March 24, 2012

CascadingDropDown SelectedIndexChanged FormView

Hi all,

I just found out that if I put a cascadingDropDownList with some dropDownLists, that have the OnSelectedIndexChanged event, inside a FormView, that event doesn't fire at the first time for the first dropdownlist.

This code works fine:

Ilha:
<asp:DropDownList ID="ddlIlhas" runat="server" OnSelectedIndexChanged="ddlIlhas_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<br /
Concelho:
<asp:DropDownList ID="ddlConcelhos" runat="server" OnSelectedIndexChanged="ddlConcelhos_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<br /
<atlasToolkit:CascadingDropDown ID="ddlPanel" runat="server">
<atlasToolkit:CascadingDropDownProperties ID="propIlha" Category="Ilha" LoadingText="[A carregar...]" PromptText="Escolher..." ServiceMethod="GetIlhas" TargetControlID="ddlIlhas" ServicePath="/EDA.SGI.Website/WebService.asmx" />
<atlasToolkit:CascadingDropDownProperties ID="propConcelho" Category="Concelho" LoadingText="[A carregar...]" ParentControlID="ddlIlhas" PromptText="Escolher..." ServiceMethod="GetConcelhosByIlha" ServicePath="/EDA.SGI.Website/WebService.asmx" TargetControlID="ddlConcelhos" />
</atlasToolkit:CascadingDropDown>
</InsertItemTemplate>
But if I put it inside an InsertItemTemplate of a FormView, when I change the selected index of the first DDL at the first time, it doesn't go to theddlIlhas_SelectedIndexChanged handler. Anyone has any idea of what is going on here?Hi i am having exactly the same problem. I've been investigating this problem and it only seems to happen when used within the FormView. I'm quite new to the ajax control toolkit but if i find a solution i will let you know. Hope this helps.
The syntax above (CascadingDropDownProperties) indicates that you're using a quite old build of both ASP.NET AJAX and the AJAX Control Toolkit. Please try upgrading to ASP.NET AJAX 1.0 and Toolkit 10301, both of which are available fromhttp://asp.net/ as we've made numerous improvements since the old builds you seem to be using. Thank you!

Hi i am using the latest build and the problem still exists. I have uploaded the sample website with a few additions to show you:

http://www.flixon.com/AjaxControlToolkit.rar

Within the CascadingDropDown folder in the sample website there's now two new files:

Test.aspx - Without FormView (SelectedIndexChanged works fine)

Test2.aspx - With FormView (SelectedIndexChanged doesn't fire on first change)

Appreciate if you could help. Thanks


Sorry, I haven't managed to track this down all the way and I've run out of time just now. It definitely seems to be related to CascadingDropDown somehow since adding a plain DropDownList doesn't show the problem. I've tried commenting out the two event handlers in CascadingDropDownBehavior, but that didn't seem to do the trick. A quick web search turned up the following two articles which seem like they may provide a clue:

http://www.mikepope.com/blog/displayblog.aspx?permalink=1629

http://www.manuelabadia.com/blog/PermaLink,guid,a2abee08-bb7f-4fe5-8a24-6e56da99172a.aspx

If nothing else, pleaseopen a work item to track this bug. Thank you!


Hi, i added a work item a few weeks back:

http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=9454

Nothing has been posted yet. I will take a look at the posts you provided hopefully later today. Thanks for your help.


Hi, i've had a look but this goes straight over my head. If someone does find a solution then that would be great.

FYI, I just updatedwork item 9454 with the following notes:

Ted and I looked into this some just now. What appears to ultimately be the problem is that CascadingDropDown (and, in fact, ExtenderBase from which it derives) isn't seeing its CascadingDropDown_ClientStateValuesLoaded/Page_PreLoad method getting called when placed in a FormView's template. That ends up causing some different behavior due to the contents of the DropDownList being empty at first. The following page goes into some more detail about how the page lifecycle is different within a template and so this is probably a more general issue we should review for the Toolkit as a whole:http://msdn2.microsoft.com/en-us/library/ms178472.aspx.

What's good is that adding the following as the contents of the DropDownList seems to work around the problem for now (it's an empty ListItem that'll get replaced by CascadingDropDown once it populates the list): "<asp:ListItem></asp:ListItem>". With that, the sample code in Test2.aspx in the RAR fromhttp://forums.asp.net/thread/1671609.aspx works as expected.


Hi David

Thanks for your attention with this problem thus far. I am having a similar problem to this, but wherever I search, I get redirected back to this posting, so I'm adding my comments here. I am trying to use a set of 4 CascadingDropDowns to select a car model (sound familiar?Smile ) . When the user selects the final drop-down, I want to create a set of check boxes based on the last drop-down's value. I am not using a FormView, just a simple form. The SelectedIndexChanged event is not firing straight away. I have another field in the form (vehicle registration date), on which the check box set also depends, so I have an OnTextChanged event set for this too. With me so far? Now, if I fill the drop-downs in a cascade using a modal window (all of which seems to work nicely), the SelectedIndexChanged event is not firing on the last drop-down. If, however, after this, I then change my text box value, the SelectedIndexChanged event for the drop-down chooses this moment to fire, followed by the OnTextChanged event for the text box. It's as if the event is getting held up or saved for later use. Is this all part of the same problem? Is there a work around I can use?

Here's my page code:

<span class="oneline" id="spDVLALookup" runat="server" visible="false"> <asp:Button ID="btnDVLALookup" Text="DVLA Lookup" runat="server" Visible="false" /></span><span class="oneline"> <span class="txtName">Manufacturer: </span><asp:DropDownList ID="ddManuf" runat="server" Width="300"> </asp:DropDownList></span><br /><span class="oneline"> <span class="txtName">Range: </span><asp:DropDownList ID="ddRange" runat="server" Width="300"></asp:DropDownList></span><br /><span class="oneline"> <span class="txtName">Model: </span><asp:DropDownList ID="ddModel" runat="server" Width="300"></asp:DropDownList></span><br /><span class="oneline"> <span class="txtName">Derivative: </span> <asp:DropDownList ID="ddDeriv" AutoPostBack="true" OnSelectedIndexChanged="ddDeriv_SelectedIndexChanged" runat="server" Width="300"> <asp:ListItem></asp:ListItem> </asp:DropDownList></span><br /><span class="oneline"> <span class="txtName">Date First Registered: </span> <asp:TextBox ID="tb1stRegDate" runat="server" Width="300" AutoPostBack="true" OnTextChanged="tb1stRegDate_TextChanged" /></span><br /><cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddManuf" Category="Manuf" PromptText="-- Manufacturer --" LoadingText="[Loading manufacturers...]" ServicePath="~/Services/CAPData.asmx" ServiceMethod="GetData" /><cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="ddRange" Category="Range" PromptText="-- Range --" LoadingText="[Loading ranges...]" ServicePath="~/Services/CAPData.asmx" ServiceMethod="GetData" ParentControlID="ddManuf" /><cc1:CascadingDropDown ID="CascadingDropDown3" runat="server" TargetControlID="ddModel" Category="Model" PromptText="-- Model --" LoadingText="[Loading models...]" ServicePath="~/Services/CAPData.asmx" ServiceMethod="GetData" ParentControlID="ddRange" /><cc1:CascadingDropDown ID="CascadingDropDown4" runat="server" TargetControlID="ddDeriv" Category="Deriv" PromptText="-- Derivative --" LoadingText="[Loading derivatives...]" ServicePath="~/Services/CAPData.asmx" ServiceMethod="GetData" ParentControlID="ddModel" />
 Here's the code to enable the button at the top: 
// Add the DVLA lookup buttonif (myVt.VIN.Length > 0 || myVt.Registration.Length > 0){ spDVLALookup.Visible =true; btnDVLALookup.Visible =true; btnDVLALookup.OnClientClick ="this.value='Please Wait'; this.disabled=true; DVLALookup(this, '" + myVt.VIN +"', '" + myVt.Registration +"');";}

Here's the JavaScript which does the modal window lookup (this JavaScript is not in the page Head because this page sits in a Master page):

function DVLALookup(button, vin, reg){ aryValues = new Array(); button.disabled = true; button.value = "Please Wait"; var url = "../../ExperianCapData/GetExperianData.aspx?vin=" + vin + "?istration=" + reg; if (navigator.appName != "Netscape") { lleft = (screen.availWidth/2) + 80; ttop = (screen.availHeight/2)-250; } strTemp = window.showModalDialog(url,aryValues,"dialogWidth:400px;dialogHeight:500px;dialogLeft:"+lleft+"px;dialogTop:"+ttop+"px;center:no;resizable:no;status:no;"); button.disabled = false; button.value = "DVLA Lookup"; if (strTemp.length > 0 && document.forms[0].ctl00_main_hfCapCode != null) { document.forms[0].ctl00_main_hfCapCode.value = strTemp; }}

Actually, I've fixed this by putting the value from the modal window (as you might have guessed from the last line of my JavaScript) into a hidden field which fires a OnValueChanged event, which in turn populates the drop-downs with the correctly selected items. I then have a logic check in my SelectedValueChanged method for the final drop-down ("derivative"), which only creates my set of check boxes for the SelectedValueChanged event if the value of the bottom drop-down is different from the one in the hidden field. This allows users to select a derivative manually (i.e. not via the modal window lookup). Also, if the SelectedValueChanged event gets delayed and fired at the same time (well OK just before) the ValueChanged event for my registration date field, it will see that its value is the same as the hidden one, so it won't try to set off the creation of the check boxes.

It's a bit clumsy, but it works. Of course, in the future I might try to split this form into TabPanels or AccordionPanes - although there was a problem with the latter, which I've forgotten. Meanwhile, if anyone can see an obvious flaw in my logic or a better way to do this, or even solve why the drop-down SelectedValueChanged event is getting delayed by one postback, please feel free to comment

Cheers, Mundo

Wednesday, March 21, 2012

CascadingDropDown OnSelectedIndexChanged event not firing

Help!!!

I have 4 drop down list boxes that are extended by the CascadingDropDown control. All of the controls populate in sequence. I am using the OnSelectedIndexChanged event of the 4th DDL to trigger an UpdatePanel. I want to take the selection from the DDL (cmbPart) and add the item to the ListBox (lbParts). When I change the selection in cmbPart, no event fires. When I press the button on the panel (btnRemovefromList) the cmbPart_SelectedIndexChanged event DOES fire before the btnRemovefromList_Click event. I have also tried to use OnSelectedIndexChanged to fire a client side javascript function and that does not fire either. However, the onblur and onclick events DO fire.

According to previous posts on this topic, it was fixed. I have the 1.0.60914.0 version of the AtlasControlToolkit.dll installed along with version 2.0.50727.60725 of Microsoft.Web.Atlas.dll.

Ken J.

Here is the code:

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"EnableEventValidation="false"%>

<%@dotnet.itags.org.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"/>

<div>

Year<asp:dropdownlistid="cmbFrom"tabIndex="2"runat="server"Width="120px">

</asp:dropdownlist>

<atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server">

<atlasToolkit:CascadingDropDownProperties

TargetControlID="cmbFrom"

Category="Year"

LoadingText="{Loading Years...}"

PromptText="Select a Year"

ServicePath="EOLDataService.asmx"

ServiceMethod="GetYears"

/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="cmbMake"

ParentControlID="cmbFrom"

Category="Make"

LoadingText="{Loading Makes...}"

PromptText="Select a Make"

ServicePath="EOLDataService.asmx"

ServiceMethod="GetMakes"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="cmbModel"

ParentControlID="cmbMake"

Category="Model"

LoadingText="{Loading Models...}"

PromptText="Select a Model"

ServicePath="EOLDataService.asmx"

ServiceMethod="GetModels"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="cmbPart"

ParentControlID="cmbModel"

Category="Part"

LoadingText="{Loading Parts...}"

PromptText="Select Parts"

ServicePath="EOLDataService.asmx"

ServiceMethod="GetParts"/>

</atlasToolkit:CascadingDropDown>

Make<asp:dropdownlistid="cmbMake"tabIndex="3"runat="server"Width="215px"></asp:dropdownlist>

Model<asp:dropdownlistid="cmbModel"tabIndex="4"runat="server"Width="250px"></asp:dropdownlist>

<INPUTid="txtPartType"type="hidden"runat="server"NAME="txtPartType">

<asp:labelid="lparterr"runat="server"Width="216px"ForeColor="Red"></asp:label>

<atlas:UpdatePanelID="upParts"runat="server"Mode="conditional">

<ContentTemplate>

Part<asp:DropDownListID="cmbPart"runat="server"Width="250px"OnSelectedIndexChanged="cmbPart_SelectedIndexChanged"></asp:DropDownList>

Selected Parts<asp:ListBoxid="lbSelected"tabIndex="10"runat="server"Width="215px"Height="85px"SelectionMode="Multiple"></asp:ListBox>

<asp:Buttonid="btnRemovefromList"style="WIDTH: 54px; font-size:xx-small"tabIndex="9"Text="Remove"

runat="server"onclick="btnRemovefromList_Click"/>

</ContentTemplate>

<Triggers>

<atlas:ControlEventTriggerControlID="cmbPart"EventName="SelectedIndexChanged"/>

<atlas:ControlEventTriggerControlID="btnRemoveFromList"EventName="Click"/>

</Triggers>

</atlas:UpdatePanel>

</div>

</form>

<scripttype="text/xml-script">

<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

<references>

</references>

<components>

</components>

</page>

</script>

</body>

</html>

And the code behind:

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid cmbPart_SelectedIndexChanged(object sender,EventArgs e)

{

lparterr.Text ="test";

}

protectedvoid btnRemovefromList_Click(object sender,EventArgs e)

{

lparterr.Text ="Test";

}

}

Maybe have a look atthis post?

Thanks David.

I found that the final DDL had to have AutoPostBack set to true. I also found that using the UpdatePanel to contain only the control I want updated by the ControlEventTrigger. If the DDL controls are contained in the UpdatePanel you will see the CascadingDropDown extender refresh each of the DDLs.

Ken J.