Showing posts with label dropdownlists. Show all posts
Showing posts with label dropdownlists. Show all posts

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 questions

I have 2 DropDownLists. One for categories and the other one for subcategories. When I change a category I want the subcategories to change. I thought this could be accomplished using the CascadingDropDown extender but I'm facing some problems.

I have populated (in the Page_Load method) both dropdownlists but the web service gets called to populate the dropdownlists. Is there any way to make the extender only call the webservice when the selection changes if it's populated with data?

Another question is why the webservice is called 3 times at start up, one for the categories (knownCategoryValues = "", category = "categories"), and two for the subcategories (knownCategoryValues = "categories:", category = "subcategories" and knownCategoryValues = "categories:1", category = "subcategories").

I thought it would be called twice not three times.

BTW, there is a helper method to return values using an xml document:

AtlasControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument

please add something similar to extract values from a DataTable.

Thanks.

The short answer is that we need to do some optimization around how many times the webservice is called. It's currently called three times because:

1) Once to populate the first list

2) Once to populate the second list

3) Once when the second list detects the value of the first list has changed

So there's some work do be done, and what you're seeing is an early version. In any case, you should apply some caching to your web service to improve performance (seehttp://support.microsoft.com/?scid=kb;en-us;318299).


Thanks for the reply Shawn but my main problem was this:

I have populated (in the Page_Load method) both dropdownlists but the web service gets called after to populate again the dropdownlists.

Is there any way to make the extenderonlycall the webservice when the selection changes if the dropdownlist is already populated with data?

And now that you have mentioned caching the web service. I was already caching my web service but I was wondering if Atlas does some kind of client caching when calling a web service if the web service is cached?

Thanks,
Manu


Yeah - the fix in the toolkit is pretty easy. Open CascadingDropDownBehavior.js, and find the "_onParentChange" method. Replace it with this:

var _lastParentValues;this._onParentChange = function() { var e =this.control.element;// Create the known category/value pairs string for sending to the helper web service // Follow parent pointers so that the complete state can be sent // Format: 'name1:value1;name2:value2;...' var knownCategoryValues =''; var parentControlID = _parentControlID;while (parentControlID) { var parentElement = document.getElementById(parentControlID);if (parentElement && (-1 != _parentElement.selectedIndex)) { knownCategoryValues = parentElement.CascadingDropDownCategory +':' + parentElement.options[parentElement.selectedIndex].value +';' + knownCategoryValues; parentControlID = parentElement.CascadingDropDownParentControlID; }else { parentControlID =null; } }if (knownCategoryValues !='' && _lastParentValues == knownCategoryValues) {return; } _lastParentValues = knownCategoryValues;// Call the helper web service Sys.Net.ServiceMethod.invoke( _servicePath, _serviceMethod,null, {'knownCategoryValues' : knownCategoryValues,'category' : _category }, Function.createDelegate(this, _onMethodComplete), Function.createDelegate(this, _onMethodTimeout), Function.createDelegate(this, _onMethodError), Function.createDelegate(this, _onMethodAborted),this ); }

It is not working Shawn.

I have made a simple example so you can test it yourself quickly:

---- BEGIN Example.aspx ---

<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Example.aspx.cs"Inherits="Example"%>

<%@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="cc1"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

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

<div>

<cc1:cascadingdropdownid="CascadingDropDown1"runat="server">

<cc1:CascadingDropDownPropertiesTargetControlID="ddlCategorias"Category="categorias"ServiceMethod="GetCategorias"ServicePath="Example.asmx"/>

<cc1:CascadingDropDownPropertiesTargetControlID="ddlSubcategorias"Category="subcategorias"ServiceMethod="GetSubcategorias"ServicePath="Example.asmx"ParentControlID="ddlCategorias"/>

</cc1:cascadingdropdown>

</div>

<atlas:ScriptManagerID="ScriptManager1"runat="server">

</atlas:ScriptManager>

<asp:DropDownListID="ddlCategorias"runat="server"DataTextField="Nombre"DataValueField="IdCat">

</asp:DropDownList>

<asp:DropDownListID="ddlSubcategorias"runat="server"DataTextField="Nombre"DataValueField="IdCat">

</asp:DropDownList>

</form>

</body>

</html>

---- END Example.aspx ---


---- BEGIN Example.aspx.cs ---

using System;

using System.Data;

using System.Configuration;

using System.Collections;

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;

publicpartialclassExample : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

ddlCategorias.DataSource = GetCategoriasPrimerNivel();

ddlCategorias.DataBind();

ddlCategorias.SelectedValue ="1";

ddlSubcategorias.DataSource = GetSubcategorias(1);

ddlSubcategorias.DataBind();

ddlSubcategorias.SelectedValue ="10";

}

privateCategoria[] GetCategoriasPrimerNivel()

{

Categoria[] categorias =newCategoria[5];

for (int i = 0; i < categorias.Length; i++) {

categorias[i] =newCategoria(i,"CAT " + i);

}

return categorias;

}

privateCategoria[] GetSubcategorias(int p)

{

Categoria[] subcategorias =newCategoria[10];

for (int i = 0; i < subcategorias.Length; i++) {

subcategorias[i] =newCategoria(i + 5,"SUBCAT (" + p +", " + i +")");

}

return subcategorias;

}

}

---- END Example.aspx.cs ---

---- BEGIN Example.asmx ---

<%

@.WebServiceLanguage="C#"CodeBehind="~/App_Code/Example.cs"Class="Example" %>

---- END Example.asmx ---

---- BEGIN Example.cs ---

using System;

using System.Web;

using System.Collections;

using System.Collections.Specialized;

using System.Web.Services;

using System.Web.Services.Protocols;

///<summary>

/// Summary description for Example

///</summary>

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

publicclassExample : System.Web.Services.WebService {

public Example () {

//Uncomment the following line if using designed components

//InitializeComponent();

}

[WebMethod]

public AtlasControlToolkit.CascadingDropDownNameValue[] GetCategorias(string knownCategoryValues,string category)

{

// Get a dictionary of known category/value pairs

StringDictionary knownCategoryValuesDictionary = AtlasControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

Categoria[] categorias = GetCategoriasPrimerNivel();

AtlasControlToolkit.CascadingDropDownNameValue[] returnValue =new AtlasControlToolkit.CascadingDropDownNameValue[categorias.Length];

for (int i = 0; i < categorias.Length; i++) {

returnValue[i] =new AtlasControlToolkit.CascadingDropDownNameValue("WS_" + categorias[i].Nombre, categorias[i].IdCat.ToString());

}

return returnValue;

}

[WebMethod]

public AtlasControlToolkit.CascadingDropDownNameValue[] GetSubcategorias(string knownCategoryValues,string category)

{

// Get a dictionary of known category/value pairs

StringDictionary knownCategoryValuesDictionary = AtlasControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);

string str = knownCategoryValuesDictionary["categorias"];

Categoria[] subcategorias = GetSubcategorias(Int32.Parse(str));

AtlasControlToolkit.CascadingDropDownNameValue[] returnValue =new AtlasControlToolkit.CascadingDropDownNameValue[subcategorias.Length];

for (int i = 0; i < subcategorias.Length; i++) {

returnValue[i] =new AtlasControlToolkit.CascadingDropDownNameValue("WS_" + subcategorias[i].Nombre, subcategorias[i].IdCat.ToString());

}

return returnValue;

}

privateCategoria[] GetCategoriasPrimerNivel()

{

Categoria[] categorias =newCategoria[5];

for (int i = 0; i < categorias.Length; i++) {

categorias[i] =newCategoria(i,"CAT " + i);

}

return categorias;

}

privateCategoria[] GetSubcategorias(int p)

{

Categoria[] subcategorias =newCategoria[10];

for (int i = 0; i < subcategorias.Length; i++) {

subcategorias[i] =newCategoria(i + 5,"SUBCAT (" + p +", " + i +")");

}

return subcategorias;

}

}

---- END Example.cs ---

Note that I have bound both dropdownlists at Page_Load with values CAT XXX and SUBCAT XXX.

However when you run the sample you get WS_CAT XXX and WS_SUBCAT XXX that are the values returned by the web service.


Hi Manuel,

I think we've fixed the issue you're having with the latest version of the toolkit. I'd recommend you get that installed and see if it makes it work.

Thanks,
Ted

CascadingDropDown not populating

Hi

I'm trying to use the CascadingDropDown with a database in VB, using page methods.

My three DropDownLists are drpProject, drpFixFor and drpFixForSub. The drpProject control is populated fine when the page loads; and I'd expect the drpFixFor control to be populated when drpProject is changed, however, this is not happening.

The drpFixFor control is being enabled, but not populated - my "GetFixForList" function doesn't appear to be calledat all. (I put a breakpoint in it, and the breakpoint isn't hit.)

Interestingly, if I remove ParentControlID="drpProject" from drpFixFor's extender, the function is called as expected when the page loads.

My aspx page is:

<%

@dotnet.itags.org.PageLanguage="VB"MasterPageFile="~/MasterPage.master"AutoEventWireup="false"CodeFile="Test.aspx.vb"Inherits="Test"Title="" %>

<%

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

<

asp:ContentID="Content1"ContentPlaceHolderID="cphBody"runat="Server">
<table> <tr> <tdstyle="width: 100px">Project:</td> <td><asp:DropDownListID="drpProject"runat="server"/></td> </tr> <tr> <tdstyle="width: 100px">Fix For:</td> <td><asp:DropDownListID="drpFixFor"runat="server"/></td> </tr> <tr> <tdstyle="width: 100px">Fix For Sub:</td> <td><asp:DropDownListID="drpFixForSub"runat="server"/></td> </tr></table><atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server"> <atlasToolkit:CascadingDropDownPropertiesTargetControlID="drpProject"Category="Project"PromptText="(Select One)" ServiceMethod="GetProjectList"/> <atlasToolkit:CascadingDropDownPropertiesTargetControlID="drpFixFor"Category="FixFor"PromptText="(Select One)"ParentControlID="drpProject"ServiceMethod="GetFixForList"/> <atlasToolkit:CascadingDropDownPropertiesTargetControlID="drpFixForSub"Category="FixForSub"PromptText="(Select One)"ParentControlID="drpFixFor"ServiceMethod="GetFixForSubList"/></atlasToolkit:CascadingDropDown>

</

asp:Content>

And my Code Behind page is:

Imports

AtlasControlToolkit

Imports

System.Web.Services

Partial

Class Test Inherits System.Web.UI.Page

<WebMethod()> _

PublicFunction GetProjectList(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue() Dim valuesAsNew Generic.List(Of CascadingDropDownNameValue) ForEach myProjectAs ProjectIn Project.GetList

values.Add(

New CascadingDropDownNameValue(myProject.Name, myProject.ID)) Next Return values.ToArray EndFunction

<WebMethod()> _

PublicFunction GetFixForList(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue() Dim valuesAsNew Generic.List(Of CascadingDropDownNameValue) ' Hardcode to Project "2" for debugging ForEach myFixForAs FixForIn FixFor.GetList(2)

values.Add(

New CascadingDropDownNameValue(myFixFor.Name, myFixFor.ID)) Next Return values.ToArray EndFunction

End

Class

Note: "Project" and "FixFor" are objects defined in my App_Code folder, and their "GetList" functions return data from the SQL database.

Any ideas?

Thanks,
Andrew

I am also facing some issues with the cascadingdropdown extender, my question is that what if my database schema is such that i dont have ID for the fields in the drop downs, cant i fetch the value in the second drop down with the string value in the first drop down. As i understand this, ID seems to be added mandatorily in this extender.

-Pratibha


I don't see anything wrong with your code - what happens if you change all three service method's to call the one that's workng? Does it get called then?

Pratibha - I don't understand your question. ID isn't added by the extender at all - you can put whatever you want into the value field of the CascadingDropDownNameValue.


hey shawn, now i get it..hadnt looked carefully through the tool kit code earlier. It makes sense now and the cascadingdropdown works perfectly :)
Cool!

Hi

I've tried setting all three service methods to call GetProjectList, and still no luck - the function's called once when the page is loaded to populate the first DropDown, and not called for the others.

Thanks,
Andrew


To fix this, you need to add EnableEventValidation="false" to your Page directive. This should be a FAQ for CascadingDropDown, but basically ASP.NET tries to make sure that postbacks don't contain stuff they shouldn't based on what it knows about the page it sent down. Well, CDD is all about sending back data that wasn't in the page to begin with, so this feature needs to be disabled for pages that use it.

That's the good news. :) The bad news (or better news depending on how you see it) is that this should have been easier to debug. CDD tries to populate the list with error details when an error occurs (see _onMethodError), but it doesn't because a change some time ago to use name/value pairs for the data type wasn't applied to the error methods. I've logged this for fixing in the next release.

But for now, your issue should be trivially solvable by flipping EnableEventValidation as I note above.

Thanks!


Fantastic - that did the job!

Thanks
Andrew


nice1 David,

that had really thrown me, thought it was a vb.net thing. the debugging experience on this could definitely be improved on but at least it's in the forums.

thanks

I've been trying to get this example to work so as I can use similar in my own pet project.

Would anyone be kind enough to tell\show me how to create the "Projects" and "FixFor" objects which are defined in the App_Code folder.

I'm getting errors on this line

ForEach myProjectAs ProjectIn Project.GetData

How do I define Project in the TableAdapter?

Rgds

DOShea


Hi,

My parent dropdown itself is not population. I addedEnableEventValidation="false" in page tag. Still no luck.

If i work in " atlas web project", I am able sccess with cascading dropdown. But if i try to do with existing project, i am not able to. No error but first dropdown itself not populating.

I added in web.config

<

pages>

<

controls>

<

addnamespace="Microsoft.Web.UI"assembly="Microsoft.Web.Atlas"tagPrefix="atlas"/>

<

addnamespace="Microsoft.Web.UI.Controls"assembly="Microsoft.Web.Atlas"tagPrefix="atlas"/>

</

controls>

...

</

pages>

This is my aspx page code:

<%

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

<%

@.RegisterAssembly="AtlasControlToolkit"Namespace="AtlasControlToolkit"TagPrefix="atlasToolkit" %>
<formid="form1"runat="server"><atlas:ScriptManagerID="ScriptManager1"runat="server"/><div><asp:DropDownListID="DropDownList1"runat="server"></asp:DropDownList><asp:DropDownListID="DropDownList2"runat="server"></asp:DropDownList></div><atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server"><atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList1"Category="Make"PromptText="Please select a make"ServiceMethod="GetDropDownContentsPageMethod"/><atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList2"Category="Model"PromptText="Please select a model"ServicePath="CarService.asmx"ServiceMethod="GetProductGroups"ParentControlID="DropDownList1"/></atlasToolkit:CascadingDropDown></form>

.Vb File:

<WebMethod()> _

PublicFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()

Dim valuesAs List(Of CascadingDropDownNameValue) =New List(Of CascadingDropDownNameValue)

values.Add(

New CascadingDropDownNameValue("A","1"))

values.Add(

New CascadingDropDownNameValue("B","2"))

values.Add(

New CascadingDropDownNameValue("C","3"))Return values.ToArrayEndFunction

My WebService (CarService.vb):

<WebMethod()> _

PublicFunction GetProductGroups(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()Dim kvAs StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)Dim valuesAs List(Of CascadingDropDownNameValue) =New List(Of CascadingDropDownNameValue)Dim ProvinceIdAsIntegerIf (kv.ContainsKey("Make")And Int32.TryParse(kv("Make"), ProvinceId))ThenIf ProvinceId = 1Then

values.Add(

New CascadingDropDownNameValue("a","1"))ElseIf ProvinceId = 2Then

values.Add(

New CascadingDropDownNameValue("b","1"))EndIfEndIfReturn values.ToArrayEndFunction

Any help is highlyAppreciated.

Regards

kant.


My reply from the private email about this issue:

"The web.config for an Atlas has additional settings that aren't present in a default web.config. It sounds like you need to add one or more of those settings to your site's web.config. You might find the windiff utility helpful in identifying the changes. Hope this helps!"


Thanks David. I am able to solve by adding aditional attributes.

I have another prob with in the same page. I added a gridview to that page having Edit & Delete buttons.

When ever my page is postback(by clicking button or by grid events ) , it's refreshing twice. Any Idea?

I am usingCollapsiblePanel, CascadingDropDownin that page.

kindly reply me if you come across this probulem.

Regards

Kant.


Hi,

This is my scenario.

In production server (win2003 with IIS 6.0, asp.net 2.0 and asp.net 1.1 coexist),
My drop downs appear blank if I try to use web services to provide the data.
If I use built in page methods and I got 'sys' is undefined.

In development pc, (XP with IIS 5.1, asp.net 2.0 and asp.net 1.1 coexist),
Both web services and page methods work without any problem.

Web.config in both machine were identical.

Does anyone have any idea why?

Thanks in advance.

Michael


"Sys undefined" suggests that Atlas itself may not be installed/configured correctly on that server.

CascadingDropDown Not Cascading

I have wired 2 dropdownlists to the cascadingdropdown controls. My page code looks like this:

1<asp:DropDownList ID="StateDropDownList" runat="server" />2<ajax:CascadingDropDown ID="StateDropDownListCascadingDropDown" runat="server" Enabled="True" Category="StateName"3 PromptText="Select a state" ServiceMethod="GetDropDownStates" ServicePath="~/Site_Services/Datasets.asmx"4 TargetControlID="StateDropDownList" />56<asp:DropDownList ID="CountyDropDownList" runat="server" />7<ajax:CascadingDropDown ID="CountyDropDownListCascadingDropDown" runat="server" Enabled="True" Category="County"8 PromptText="Select a county" ServiceMethod="GetDropDownCounties" ServicePath="~/Site_Services/Datasets.asmx"9 ParentControlID="StateDropDownList" TargetControlID="CountyDropDownList" />

I've simplified the second web method to try anything to get the 2nd dropdownlist to work and no matter what, it still doesn't work. Here is the simplified method:

1 [System.Web.Services.WebMethod]2 [System.Web.Script.Services.ScriptMethod]3public CascadingDropDownNameValue[] GetDropDownCounties(string knownCategoryValues,string category)4 {5 List<CascadingDropDownNameValue> values =new List<CascadingDropDownNameValue>();6 values.Add(new CascadingDropDownNameValue("Test","Test"));7return values.ToArray();8 }

Here's what is posted:

The server returns no response. Any ideas?

j_gaylord:

5List values =new List();

Are you referring a generic List<> collection?

I got an article on Cascading dropdownlist athttp://www.aspalliance.com/1183 . Check it

Thanks


Yes. The code didn't print out properly as the Code screen in the forums ommited my < and >. I updated the code above. You'd think that it would work regardless because no matter what the values are, a value is being added to the collection. However, that's not the case.


any ideas?

nudge


Two things I would check are:

1. The webservice is decorated with [System.Web.Script.Services.ScriptService] attribute.
2. The correct web.config file and the AjaxControlToolkit.dll binary.

Thanks


Both of them are correct. I already have one drop down working. Its just the second one who's parent is the first is not.


j_gaylord:

Both of them are correct. I already have one drop down working. Its just the second one who's parent is the first is not.

In such case, the second dropdown should also fill, as the method [GetDropDownCounties] you wrote has nothing to do with the parent dropdownvalue. I have tested your code and its working fine for me. You messed up something for sure.

Thanks


Thanks for the positive insight. Any further suggestions?Wink

CascadingDropDown needs to fire "SelectedIndexChanged" from client-side

It seems I always end up with more questions than answers...

So...here's the scenario this time.

I've got two dropdownlists, Make (ddlMake) and Model (ddlModel) with a CascadingDropDownExtender attached to ddlModel. Obviously, when the user changes the Make, I need to retrieve the appropriate Models based on the selection. No problem, that part works just fine.

The twist is this: When I load this up into a ModalPopup, a record is going to (pardon the pun) drive what's being populated into ddlMake. I'm using Javascript to .show() my ModalPopup after I've looked up the record, so the code goes a little like this:

function showModal(object)
{
var _ddlMake = document.getElementById("<%= ddlMake.ClientID %>");
var _ddlModel = document.getElementById("<%= ddlModel.ClientID %>");

// Dummy for now, will be pulled from the loaded record
_ddlMake.options[4].selected = true;
_ddlMake._onParentChange(null,null);

var _popup = $find(object);
_popup.show();
}


Some of the posts I've seen suggested the _onParentChange(null,null), but Firebug is barking saying "_ddlMake._onParentChange is not a function". Granted, it's one of the internals of the CascadingDropDown, but others have stated that this is the way to do it.

What I'm wondering is how to do this. I can't believe that I'm the only person to have ever thought of needing to set/fire these events from the client-side. I'd love some help on this one, that's for sure!

Thanks in advance,

Ric

Bump...still needing some help...

CascadingDropDown in repeater

I have three dropdownlists, three cascadingdropdown extenders, and updatepanel within a repeater. I need to update a label control inside of the updatepanel when the selectedindexchanged event fires for the last dropdown. The problem I'm having is that the event doesn't seem to fire the first time the selectedindex is changed. It works as expected after changing the first time. Anyone have any ideas as to why this is happening. Here is my code.

<asp:RepeaterID="uxPublicationRepeater"OnItemDataBound="PublicationRepeater_ItemDataBound"OnItemCommand="Pub_ItemCommand"runat="server">

<ItemTemplate>

<ajax:CascadingDropDownID="uxPublicationCascading"runat="server"

Category="Publication"

ServiceMethod="GetPublicationsByMarket"TargetControlID="uxPubDropDownList"

ParentControlID="uxMarketDropDownList"PromptText="Select.."LoadingText="Loading.."/>

<ajax:CascadingDropDownID="uxPublicationYearCascading"runat="server"

Category="PublicationYear"PromptText="Select.."LoadingText="Loading.."

ServicePath="~/Services/LookupWebService.asmx"ServiceMethod="GetYearsByPublication"

TargetControlID="uxPublicationDateDropDownList"ParentControlID="uxPubDropDownList"/>

<asp:DropDownListID="uxMarketDropDownList"runat="server"/>

<asp:DropDownListID="uxPubDropDownList"runat="server"/>

<asp:DropDownListID="uxPublicationDateDropDownList"OnSelectedIndexChanged="IndexChanged"AutoPostBack="true"runat="server"/>

<asp:UpdatePanelID="uxUpdatePanel"ChildrenAsTriggers="false"UpdateMode="conditional"runat="server">

<ContentTemplate>

<asp:LabelID="uxLabel"runat="server"/>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="uxPublicationDateDropDownList"EventName="SelectedIndexChanged"/>

</Triggers>

</asp:UpdatePanel>

</ItemTemplate>

</asp:Repeater>

Thanks for the help.

Have you taken a look at the sample?http://www.asp.net/AJAX/Control-Toolkit/Live/CascadingDropDown/CascadingDropDown.aspx

This could be related to EventValidation (see http://www.asp.net/AJAX/Control-Toolkit/Live/Walkthrough/CCDWithDB.aspx specfically:"Finally, in order for the values to be submitted, EventValidation needs to be disabled for the page. EventValidation ensures that the values in each control match the values that were present when the page was rendered, but since these drop downs are populating on the client side, this is never true.")

-Damien


I tried turning event validation off and still no good. The event fires the first time if the controls are outside of the repeater, but doens't fire until the second time when inside the repeater.


No one else has ran into this problem? If I take the cascadingdropdown extender out, the events fire correctly. Just to recap, dropdownlists in a repeater, selectedindexchange event fires correctly. Dropdownlists and cascadingdropdown extenders inside a repeater the event doesn't fire until the second time the selectedindex is changed. If anyone is interested I have a small sample app that illustrates the problem.


c.barnes01:

No one else has ran into this problem? If I take the cascadingdropdown extender out, the events fire correctly. Just to recap, dropdownlists in a repeater, selectedindexchange event fires correctly. Dropdownlists and cascadingdropdown extenders inside a repeater the event doesn't fire until the second time the selectedindex is changed. If anyone is interested I have a small sample app that illustrates the problem.

Hi,

I'd like to see your small sample, it will be preferred to use NorthWind database or a fake data source built in code.


Here is a small app that illustrates the problem.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" EnableEventValidation="false" Inherits="_Default" %><%@. 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> <asp:Repeater ID="uxTestRepeater" OnItemDataBound="Repeater_DataBound" runat="server"> <ItemTemplate> <cc1:CascadingDropDown ID="uxCountriesCascading" Category="Countries" runat="server" ParentControlID="uxCountryDropDownList" TargetControlID="uxStatesDropDownList" LoadingText="Loading.." PromptText="Select.." ServiceMethod="GetScopedStates" /> <asp:DropDownList ID="uxCountryDropDownList" runat="server" /> <asp:DropDownList ID="uxStatesDropDownList" AutoPostBack="true" OnSelectedIndexChanged="SelectedIndex_Changed" runat="server" /><br /> <asp:UpdatePanel ID="uxUpdatePanel" runat="server"> <ContentTemplate> <asp:Label ID="uxStateLabel" runat="server" Text="Select a State" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="uxStatesDropDownList" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> <hr /> </ItemTemplate> </asp:Repeater> </div> </form></body></html>

using System;using System.Collections;using System.Collections.Generic;using System.Collections.Specialized;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.Services;using System.Web.Script.Services;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using AjaxControlToolkit;public partialclass _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) {this.uxTestRepeater.DataSource = GenerateRepeaterDataSource();this.uxTestRepeater.DataBind(); } }private List GenerateRepeaterDataSource() { List toReturn =new List(); toReturn.Add(new MyClass(1,"Chris"));return toReturn; }protected void Repeater_DataBound(object sender, RepeaterItemEventArgs e) { DropDownList countryDropDownList = e.Item.FindControl("uxCountryDropDownList")as DropDownList; countryDropDownList.DataSource = GenerateCountries(); countryDropDownList.DataTextField ="Value"; countryDropDownList.DataValueField ="Key"; countryDropDownList.DataBind(); }private Dictionary<int,string> GenerateCountries() { Dictionary<int,string> toReturn =new Dictionary<int,string>(); toReturn.Add(1,"USA"); toReturn.Add(2,"Canada"); toReturn.Add(3,"Mexico");return toReturn; }protected void SelectedIndex_Changed(object sender, EventArgs e) { DropDownList stateDropDown = senderas DropDownList; Label stateLabel = stateDropDown.NamingContainer.FindControl("uxStateLabel")as Label; stateLabel.Text = stateDropDown.SelectedItem.Text; } [WebMethod] [ScriptMethod]public static CascadingDropDownNameValue[] GetScopedStates(string knownCategoryValues,string category) { CascadingDropDownNameValue[] toReturn =null; StringDictionary values = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);if (values.Count == 1) {string key = values["undefined"];switch (key) {case"1": toReturn = GetStatesForUsa();break;case"2": toReturn = GetStatesForCanada();break;case"3": toReturn = GetStatesForMexico();break;default:break; } }return toReturn; }public static CascadingDropDownNameValue[] GetStatesForUsa() { CascadingDropDownNameValue[] toReturn =null; toReturn =new CascadingDropDownNameValue[5]; toReturn[0] =new CascadingDropDownNameValue("SC","1"); toReturn[1] =new CascadingDropDownNameValue("GA","2"); toReturn[2] =new CascadingDropDownNameValue("NY","3"); toReturn[3] =new CascadingDropDownNameValue("FL","4"); toReturn[4] =new CascadingDropDownNameValue("NC","5");return toReturn; }public static CascadingDropDownNameValue[] GetStatesForCanada() { CascadingDropDownNameValue[] toReturn =null; toReturn =new CascadingDropDownNameValue[5]; toReturn[0] =new CascadingDropDownNameValue("Saskatchewan","1"); toReturn[1] =new CascadingDropDownNameValue("Alberta","2"); toReturn[2] =new CascadingDropDownNameValue("British Columbia","3"); toReturn[3] =new CascadingDropDownNameValue("Nunavut","4"); toReturn[4] =new CascadingDropDownNameValue("Yukon","5");return toReturn; }public static CascadingDropDownNameValue[] GetStatesForMexico() { CascadingDropDownNameValue[] toReturn =null; toReturn =new CascadingDropDownNameValue[5]; toReturn[0] =new CascadingDropDownNameValue("Hidalgo","1"); toReturn[1] =new CascadingDropDownNameValue("Veracruz","2"); toReturn[2] =new CascadingDropDownNameValue("Puebla","3"); toReturn[3] =new CascadingDropDownNameValue("Durango","4"); toReturn[4] =new CascadingDropDownNameValue("Sonora","5");return toReturn; }}public class MyClass{private int id;public int ID {get {return id; }set { id =value; } }private string name;public string Name {get {return name; }set { name =value; } }public MyClass(int id,string name) {this.id = id;this.name = name; }}

I still haven't found a solution to this yet. Anyone have any suggestions?

Thanks


Bump


What is the full type name of the toReturn( List toReturn =new List();) object?


It should have been, List<MyClass> toReturn = new List<MyClass>();

thanks


I looked into it through, and found out that the reason is because the items are filled on client side.

1. On the first request( when isPostback is false ), there is no items in DDLState.

2. DDLState is filled when the page has been rendered in the browser

3. Select an item in the DDL to start a postback

4. The DDL tries to find the currentIndex( it's -1 since it can't be found ) and compares it with previousIndex( it's -1 since there is no item previously ) to see if a selectedChanged event should be fired. And it won't be fired because they are equal

5. On the second request, the previously posted item is kept in ViewState and subsequently added into DDLState's items collection

6. The previously index is 0 because the only item currently in DDLState matches the previous value. And currently posted item's value still doesn't exist, so currentIndex is -1. They are not equal, thus the SelectedIndexChanged event is fired.



Thanks for looking into the problem. It's weird that it works when not in a repeater.