Showing posts with label cascadingdropdown. Show all posts
Showing posts with label cascadingdropdown. Show all posts

Monday, March 26, 2012

CascadingDropDowns in VB

I'm trying to convert the CascadingDropDown list sample to VB and I'm running into a problem. When I view the page, there are no errors but the dropdown lists don't populate. It doesn't seem like the webservice is being run. The reason I say this is beacuse if I change the "ServicePath" property on the aspx page to point to a nonexistant file, I get the exact same results...No error and no data in the lists. But I figure that if the ServicePath that Im pointing at doesn't exist, I should be getting an error. Here is my code for the .vb service and the .aspx code. What am I missing?

Inherits System.Web.Services.WebServicePrivate ReadOnly _document asNew XmlDocument()Private ReadOnly _hierarchy() asString Public Sub CarsService()'Read XML data from disk _document.Load(Server.MapPath("~/App_Data/CarsService.xml")) _hierarchy(0) ="Make" _hierarchy(1) ="Model"End Sub <WebMethod()> _Public Function GetDropDownContents(ByVal knownCategoryValuesAs String,ByVal categoryAs String)As AtlasControlToolkit.CascadingDropDownNameValue()Dim knownCategoryValuesDictionary asNew StringDictionary knownCategoryValuesDictionary = AtlasControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)Return AtlasControlToolkit.CascadingDropDown.QuerySimpleCascadingDropDownDocument(_document, _hierarchy, knownCategoryValuesDictionary, category)End Function
<atlas:ScriptManager id="ScriptManager1" EnablePartialRendering="true" runat="server"></atlas:ScriptManager> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"><contenttemplate><table><tr> <td>Make</td> <td><asp:DropDownList ID="DropDownList1" runat="server" Width="170" /></td></tr><tr> <td>Model</td> <td><asp:DropDownList ID="DropDownList2" runat="server" Width="170" /></td></tr><tr> <td>Color</td> <td><asp:DropDownList ID="DropDownList3" runat="server" Width="170" /></td></tr></table><br /><asp:Button ID="Button1" runat="server" Text="I want this car" OnClick="Button1_Click" /><br /><br /><asp:Label ID="Label1" runat="server" Text="[No response provided yet]"></asp:Label></contenttemplate></atlas:UpdatePanel><atlasToolkit:CascadingDropDown id="CascadingDropDown1" runat="server"><atlasToolkit:CascadingDropDownProperties TargetControlID="DropDownList1" Category="Make"PromptText="Please select a make" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents" /><atlasToolkit:CascadingDropDownProperties TargetControlID="DropDownList2" Category="Model"PromptText="Please select a model" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents"ParentControlID="DropDownList1" /><atlasToolkit:CascadingDropDownProperties TargetControlID="DropDownList3" Category="Color"PromptText="Please select a color" ServicePath="CarsService.asmx" ServiceMethod="GetDropDownContents"ParentControlID="DropDownList2" /></atlasToolkit:CascadingDropDown></form>

Hmmm - the code looks okay to me. Two questions:

1) Does the sample website page for CascadingDropDown work okay?

2) If you put a breakpoint in the web service, can you verify that it does or doesn't work


Make sure that your Web.Config is updated to allow browser access to web services. You can find details at this link:

http://atlas.asp.net/docs/atlas/doc/services/exposing.aspx#enable

If you don't then I think you'll find that your drop-down lists will not be populated!

Hope this helps

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.

CascadingDropDownProperties - Setting SelectedValue dynamically

I have an application where I am using the CascadingDropDown Lists. I have incorporated a set of them into a control.

I want to add a property to my CascadingDropDownProperties that will set an initial "filter" for my list.

For example, if I were using the sample CDD provided on the website that gives Make, Model, Color in my application, I may want to tell my control to only select foreign or domestic makes. At this point, the control can continue on to do what it needs to.

My web method is calling a MS-SQL stored procedure, and it has an input parameter of foreign/domestic (CarClass) for selecting the available Makes.

My questions on this are as follows:

    How do I set up my CascadingdropDownProperties to add the Foreign/Domestic (CarClass) value?

    How do I set this value in the code-behind?

(I will omit my actual DropDownLists from my code.)

Here is my CascadingDropDown definition:

1 <atlasToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server">
2 <atlasToolkit:CascadingDropDownProperties
3 Category="CarClass"
4 ServicePath="~/wsSelectCar_Data.asmx" />
5
6 <atlasToolkit:CascadingDropDownProperties
7 TargetControlID="ddlMake"
8 Category="Make"
9 PromptText="Please select a Make"
10 ServiceMethod="GetMakes"
11 ServicePath="~/wsSelectCar_Data.asmx" />
12
13 <atlasToolkit:CascadingDropDownProperties
14 TargetControlID="ddlModel"
15 ParentControlID="ddlMake"
16 Category="Model"
17 PromptText="Please select a Model"
18 ServiceMethod="GetModel"
19 ServicePath="~/wsSelectCar_Data.asmx" />
20
21 <atlasToolkit:CascadingDropDownProperties
22 TargetControlID="ddlColor"
23 ParentControlID="ddlMake"
24 Category="Color"
25 PromptText="Please select a Color"
26 ServiceMethod="GetColor"
27 ServicePath="~/wsSelectCar_Data.asmx" />
28 </atlasToolkit:CascadingDropDown>

As you can see, I tried to create a property with the Category "CarClass". My Code-behind has the following to try to set the value:

1 int intCarClass =int.Parse(Session["CarClass"].ToString());
2 this.CascadingDropDown1.TargetProperties[0].SelectedValue = intCarClass.ToString();

This does not seem to work.

Thanks,
Bryan

Hi Bryan,

I'd recommend you switch to a page method and then just check whether or not you should apply the additional filter however you want.

Thanks,
Ted

Can you provide sample code for doing this?

I am not familiar with the "Page" methods.

Thanks.

CascadingDropDownProperties - Creating an extra Category/Value through code

I need to add an initial "filter" to my CascadingDropDown Lists.

How do I create a Property, and assign a value and category to it through code?

Thank you,

Bryan

I'm afraid I don't understand - could you please rephrase the question?

Saturday, March 24, 2012

CascadingDropDownList?????? :(

My project requirement says we want to use CascadingDropDown, but we dont want to create the webservice. We just want to create a public method .
Any one has an idea of how to do this.

Does any one have the answer?
Any Answers???

CascadingDropDownlist: How Do I Save the SelectedValue Back To Database

I'm using the AJAX CascadingDropDown extender inside a FormView's InsertItemTemplate.
Question: What is the correct way to save the CascadingDropDown 's selected value back to the database?

I've tried do it by setting the SelectedValue in the CascadingDropDown tag (not the DropDownList) like this:
SelectedValue='<%# Bind("SellerRegionId") %>'

However, when trying to save, this fails with error "Input string was not in a correct format."

I've been able to make it work by setting the Values dictionary in the FormView's ItemInserting() event handler, using the SelectedValue of the DropDownList control (not the extender), as follows:
e.Values["SellerRegionId"] = sellerRegionDropDownList.SelectedValue;

Is this the correct way to do this?

Thanks, in advance, for any help you can give.

Yes the latter should work and in my own opinion personally is more efficient.

CascadingDropDownList with parameters for the first dropdown contents

Hi,

I'm trying ot make use of the CascadingDropdown control but I'm having trouble figuring out how to pass the parameters I need to populate the initial (top level) DropDownList

For example, I have the following DropdownLists:

Program

SubProgram

I want the cascade to occur on the SubProgram.

The problem lies in populating the Program DropDownList. I need to populate it based on a couple integer values (ProducerID and ProductID).

How do I specify these values for use in the webmethod? I can't find any examples where the webmethod that populates the Parent DropDownList isn't doing some simple query like getting all makes of a car.

Hi,

You can use contextKey to pass additional parameters to the webmethod that is responsible for filled the dropdownlist.

Please refer to this thread: http://forums.asp.net/p/1159991/1919729.aspx#1919729

CascadingDropDownList Internal Error 500

Hi,

I am trying to use a CascadingDropDown list, the ParentDropDownList show up correctly, however, the Childdropdownlist give an error:

ChildDropDownList contains:
Prompt text
[Method error 500]

Here is the code I used:

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

</asp:ScriptManager>

<br/>

<asp:DropDownListID="DropDownListLevel6xx"

runat="server"

DataSourceID="ods_Level6"

DataTextField="LEVEL6"

DataValueField="LEVEL6"Width="126px"

>

</asp:DropDownList>

<asp:DropDownListID="DropDownListLevel7xx"

runat="server"Width="153px"

>

</asp:DropDownList>

<br/>

<br/>

<br/>

<asp:ObjectDataSource

ID="ods_Level6"

OldValuesParameterFormatString="original_{0}"

SelectMethod="GetAllLevel6"

runat="server"

TypeName="DayOnePLCS.dsLevel67TableAdapters.Hierarchy_Level72TableAdapter"

></asp:ObjectDataSource>

<ajaxToolkit:CascadingDropDownID="CascadingDropDown1"runat="server"

Category="LEVEL7"LoadingText="Please wait..."ParentControlID="DropDownListLevel6xx"PromptText="Select a level 6 filter"

TargetControlID="DropDownListLevel7xx"ServicePath="Level67Service.asmx"

ServiceMethod="GetLevel7ByLevel6Id"/>

And the web service:

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

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

[ToolboxItem(false)]

publicclassLevel67Service : System.Web.Services.WebService {

[WebMethod]publicCascadingDropDownNameValue[] GetLevel7ByLevel6Id(string knownCategoryValues,string category) {

string[] _categoryValues = knownCategoryValues.Split(':',';');

String _level6 =Convert.ToString(_categoryValues[1]);

List<CascadingDropDownNameValue> _level7list =newList<CascadingDropDownNameValue>();

DayOnePLCS.dsLevel67TableAdapters.Hierarchy_Level71TableAdapter _level7Adapter =new DayOnePLCS.dsLevel67TableAdapters.Hierarchy_Level71TableAdapter();

foreach (DataRow _rowin _level7Adapter.GetLevel7byLevel6(_level6)) {

_level7list.Add(newCascadingDropDownNameValue(_row["LEVEL7"].ToString(), _row["LEVEL7"].ToString()));

}

return _level7list.ToArray();

}

}

I have tested the web service, it produce the right result.

Thanks in advance for any help!

Not sure if this will help, this is the web.config file..

Any help will be very much appreciated...

<?xml version="1.0"?>

<configuration>


<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

<connectionStrings>

<REMOVED for sercurity reason>
</connectionStrings>

<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<globalization culture="en-GB"
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"/>


<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>


</configuration>


Hi,

Error with status code 500 indicates that there is a problem when theserver tries to process the request. There can be variant causes. Any exceptioncould be a candidate. So the problem is mainly about how to find out the realcause of the error. Here are several options:

1. Set a break point in the code that is responsible for process therequest, then debug through it to find out the exception being thrown;

2. The real error message is usually returned in the response. We can useHttp Sniffer (e.g., Fiddler) to peek into the traffic between the client andserver to find out the error message.

Then it won't betoo difficult to solve it after the cause is known.

CascadingDropDown: Pulling selected values from a cookie

I am using the CascadingDropDown extender from the AjaxControlToolkit and I was wondering if there was an easy way to set the selected value and to populate child drop downs when the page loads. I am storing a users previous selections in a cookie so when they start a new form these values are already selected. I did some looking at the CascadingDropDown code but I didn't see an easy way to accomplish this. Does anyone know an easy way to do it?

Or am I going to have to cobble some JS together to make it happen?

Thanks.

Derek

Couldn't you just do something like

myCascadingDropdownListExtender.SelectedValue = Request.Cookies("MyCookie")

on Page_Load ? It works for me.

CascadingDropDown: How to register OnChange event on client?

Hello,

I have a WebForm with three CascadingDropDown. First is the parent of second list and second is the parent of the third list. And third list has a AutoPostBack feature to populate a GridView in an UpdatePanel on the page. My challenge is clear UpdatePanel content when user change first or second lists value.

So how can I register to onChange something like event of the list on client script? Then I can use $get("UpdatePanelClientId").innerHTML="".


Regards.

Hi,

You may use the following code.

<asp:DropDownList ID="DropDownList1" runat="server" Width="170"onchange="$get('ctl00_SampleContent_UpdatePanel1').innerHTML='';"/>

You can try it on the sample website's CascadingDropDown.aspx page.

Hope this helps.

CascadingDropDown: Fire an Event

I have created a custom control that contains 3 CascadingDropDown boxes.

I would like to have the control fire a custom event when each of the "TextChanged" or "SelectedIndexChanged" events from the Drop Down items change.

I have added the appropriate "events" into my code behind, but they do not seem to fire. Does the JavaScript intercept them?

Any help would be greatly appreciated.

Thanks,
Bryan

The Changed events you rever to are server-side events that only fire when there's a postback. By design, CascadingDropDown doesn't do postbacks. So you don't get those events when using it. You could force a postback, but doing so would seem to negate many of the benefits of the CDD.

Mr. Anson,

Perhaps you could point me in a better direction for my needs.

The Custom Control that I have created consists of 3 CascadingDropDowns that allow the user to select a Location, Skill, and Supervisor (basically this is like the Make/Model/Color sample for the car.).

My control works fine when I incorporate a button to run a report on a different page. My Button_OnClick event can see what values are in my control, and it will send them to the new page.

I would like to incorporate my current control on a page to help narrow down yet another Drop Down List.

In the CDD example, after the user selects the Make/Model/Color, I would like to pull a list of Vehicles by Year to select.

How would I go about hooking up a new CDD that requires the control to have filled in the Make/Model/Color before it can go out and find it's data?

I thought that I could do something like placing the control and drop down list inside an update panel, but I am a little fuzzy on how to continue from there.

Would I need to set up an Atlas Trigger?

Any help that you can provide would be greatly appreciated. It would even help if you could point me in a better direction.

Thanks, Bryan


Could you add a ByYear CDD that has the Color CDD as its parent? That way it automatically populates when the Make/Model/Color are filled in. And it's welcome to call a completely different web service, so it can get whatever data it wants.

If my Make/Model/Color are in a seperate control, how will I be able to give my Year CDD the parent that is inside the control? Can I just expose the CDD as a public member?

I don't want to add the Year CDD into my control. A different page may want to populate a different CDD from the data that the control provides.


You could manually hook some script up to the "onchanged" event on the client-side select element, but it's probably ultimately the same problem as above with respect to how the Year can see into the control to get the right elements.

CascadingDropDown, SelectedValue in a bound form

Hey folks,

I don't know if it's been addressed, but I couldn't find the solution.

I need to databind selectedValue of a cascading dropdown. Since TargetProperties cannot be databound using <#% #> syntax, I use DataBinding event handler:

 <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" /> <asp:FormView ID="frm1" runat="server" DefaultMode="insert"> <InsertItemTemplate> <asp:Button ID="btnToggle" runat="server" OnClick="btnToggle_OnClick" Text="Toggle dropdown panel" /> <asp:Panel ID="pnlDropdown" runat="server" Visible="false"> <asp:DropDownList ID="ddl1" runat="server" /> <atlasToolkit:CascadingDropDown runat="server" ID="cdd1" OnDataBinding="cdd1_DataBinding"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddl1" ServiceMethod="GetOptions" PromptText="--Select--" Category="Options" /> </atlasToolkit:CascadingDropDown> </asp:Panel> </InsertItemTemplate> </asp:FormView> </div> </form>

With the following codebehind:

protected void btnToggle_OnClick(object sender, EventArgs args) { Panel pnlDropdown = (Panel) ((Control)sender).Parent.FindControl("pnlDropdown" ); pnlDropdown.Visible = !pnlDropdown.Visible; }protected void cdd1_DataBinding(object sender, EventArgs args) { CascadingDropDown cdd1 = (CascadingDropDown)sender; cdd1.TargetProperties[0].SelectedValue ="1"; } [WebMethod]public CascadingDropDownNameValue[] GetOptions(string knownCategoryValues,string category) { CascadingDropDownNameValue[] cddValues =new CascadingDropDownNameValue[] {new CascadingDropDownNameValue("one","1"),new CascadingDropDownNameValue("two","2") };return cddValues; }

The problem exhibits itself only if the CascadingDropDown is originally hidden.

Obviously, this isn't the production code, but it models the behaviour precisly.

Any way to solve it?

Thanks in advance,

ET

Sorry, I forgot to state the actual problem, thespecified SelectedValue is ignored if the dropdown is not visible at the time of binding. Why?

et_td:

Hey folks,

I don't know if it's been addressed, but I couldn't find the solution.

I need to databind selectedValue of a cascading dropdown. Since TargetProperties cannot be databound using <#% #> syntax, I use DataBinding event handler:

 <form id="form1" runat="server"> <div> <atlas:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" /> <asp:FormView ID="frm1" runat="server" DefaultMode="insert"> <InsertItemTemplate> <asp:Button ID="btnToggle" runat="server" OnClick="btnToggle_OnClick" Text="Toggle dropdown panel" /> <asp:Panel ID="pnlDropdown" runat="server" Visible="false"> <asp:DropDownList ID="ddl1" runat="server" /> <atlasToolkit:CascadingDropDown runat="server" ID="cdd1" OnDataBinding="cdd1_DataBinding"> <atlasToolkit:CascadingDropDownProperties TargetControlID="ddl1" ServiceMethod="GetOptions" PromptText="--Select--" Category="Options" /> </atlasToolkit:CascadingDropDown> </asp:Panel> </InsertItemTemplate> </asp:FormView> </div> </form>

With the following codebehind:

protected void btnToggle_OnClick(object sender, EventArgs args) { Panel pnlDropdown = (Panel) ((Control)sender).Parent.FindControl("pnlDropdown" ); pnlDropdown.Visible = !pnlDropdown.Visible; }protected void cdd1_DataBinding(object sender, EventArgs args) { CascadingDropDown cdd1 = (CascadingDropDown)sender; cdd1.TargetProperties[0].SelectedValue ="1"; } [WebMethod]public CascadingDropDownNameValue[] GetOptions(string knownCategoryValues,string category) { CascadingDropDownNameValue[] cddValues =new CascadingDropDownNameValue[] {new CascadingDropDownNameValue("one","1"),new CascadingDropDownNameValue("two","2") };return cddValues; }

The problem exhibits itself only if the CascadingDropDown is originally hidden.

Obviously, this isn't the production code, but it models the behaviour precisly.

Any way to solve it?

Thanks in advance,

ET


As a workaround, I found that setting SelectedValue in an FormView.ItemCreated event handler works.

Cheers,

ET

CascadingDropDown, problems selecting values

Hello,

I did some research but couldn't find a solution and I hope you can help me.
The DropDownList (there are more, but one will suffice) is populated correctly, at least when I click on it.

<asp:HiddenField ID="SomeID" OnValueChanged="VC_Method" runat="server" />
<div id="hiddenForm" style="display :none">
<asp:UpdatePanel ID="DetailUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="False" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ProjectDDL" runat="server"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown ID="CDD0" TargetControlID="ProjectDDL" Category="Project" ServicePath="CDD.asmx" ServiceMethod="GetProjects" runat="server" />

So now what this should do is, when clicking on a Link the DetailUpdatePanel becomes visible and the VC_Method of the HiddenField is executed and in this Method I want to select a certain item of the DDL. But there are no values to choose from. Now my question is, becomes the CDD only populated when I click on it and if so, how can I populate it beforehand?

Thanks in advance.

I solved the problem above, but I'm now terribly stuck.

After the user selected one item from the first dropdownlist, the second becomes active etc. Now the user decides to cancel the task and for wathever reason he starts anew. My problem now is, that I want to reset the cascading dropdownlist on client side, so that the user can only select items from the first dropdownlist. For this purpose a javascript function should be executed. I can set the dropdownlist to the value I want and also the cascading dropdownlist, but it won't affect the second and third. Thus they stay active with wrong information.

I have tried now for one day hand havn't got a clue. Please help me..

EDIT:corrected some errors


Hi Twinkybot,

My understanding of your issue is that you want the second CascadingDropDown not change while you selected the first CascadingDropDown. If I has misunderstood, please feel free to let me know.

Based on this knowledge, I think you can remove the handlers of the first CascadingDropDown and then remove the second CascadingDropDown's _parentChangeHandler. Here is the sample.

<%@. Page Language="C#" 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"
<script runat="server"
protected void Page_Load(object sender, EventArgs e)
{

}
</script
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="../WebService/CityServiceOledb.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager>
State:<asp:DropDownList runat="server" ID="dlState">
</asp:DropDownList>
City:
<asp:DropDownList runat="server" ID="dlCity" AutoPostBack="true">
</asp:DropDownList>

<cc1:CascadingDropDown ID="CascadingDropDown1" BehaviorID="myCDEState" runat="server" TargetControlID="dlState"
Category="State" ServicePath="../WebService/CityServiceOledb.asmx" ServiceMethod="GetStates" LoadingText="[Loading...]" PromptText="Please select state" UseContextKey="true" ContextKey="0,0">
</cc1:CascadingDropDown>
<cc1:CascadingDropDown ID="CascadingDropDown2" BehaviorID="myCDECity" runat="server" TargetControlID="dlCity" ParentControlID="dlState"
Category="City" PromptText="Select a city" ServicePath="../WebService/CityServiceOledb.asmx"
ServiceMethod="GetCities" LoadingText="Load Text..." >
</cc1:CascadingDropDown>

<input id="Button2" type="button" value="remove" onclick="removeCascading();"/>
<asp:Button ID="Button1" runat="server" Text="Button" />

<script type="text/javascript" language="javascript">
function removeCascading(){
$find("myCDEState").dispose();
$removeHandler($find("myCDECity")._parentElement, "change", $find("myCDECity")._parentChangeHandler);
$get("Button2").disabled = true;
}
</script>
</form>
</body>
</html>

Best regards,

Jonathan


Yes, I think you misunderstood. I want the second and third CascadingDropDown to change according to the selcetion of the first. But the Problem is, that it doesn't.

I try to explain my problem better. The user selects one item in the first DropDownList. The second becomes updated and the user is able to select one item. Now he cancels the changes and restarts the procedure.

What I want now is, that after hitting the cancel-Button, the DropDownLists must reset. I.e. in a Javascript I set the selectedIndex for the first DropDownList to 0. Corresponding to this selection the second and third should now change themselves, but it doesn't happen.

<asp:DropDownList ID="ProjectDropDownList" runat="server"></asp:DropDownList><ajaxToolkit:CascadingDropDown ID="CascadingDropDown0" TargetControlID="ProjectDropDownList" Category="Project" PromptText="Foo" ServicePath="~/CDD.asmx" ServiceMethod="GetProjects" runat="server" /><asp:DropDownList ID="TaskDropDownList" runat="server"></asp:DropDownList><ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" TargetControlID="TaskDropDownList" ParentControlID="ProjectDropDownList" Category="Task" PromptText="Foo" ServicePath="~/CDD.asmx" ServiceMethod="GetTaskForProject" runat="server" /> <asp:DropDownList ID="TaskShortDescriptionDropDownList" runat="server"></asp:DropDownList><ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" TargetControlID="TaskShortDescriptionDropDownList" ParentControlID="TaskDropDownList" Category="TaskDescription" PromptText="Foo" ServicePath="~/CDD.asmx" ServiceMethod="GetDescriptionForTask" runat="server" />
function clearForm(){ var projectDDL = document.getElementById('<%= ProjectDropDownList.ClientID%>'); projectDDL.selectedIndex = 0; //Here must be something to activate the cascade}

I found a solution and I will post this for other desperate people.

projectDropDownList.options[0] = new Option(projectName, projectId, true, false);
taskCascade._onParentChange(null, false);

CascadingDropDown, FormView, ObjectDataSource, Optimistic Concurrency and Delete

Greetings,


We have recently upgraded a web site from "atlas" July 06 to use AJAX 1.0 (1.0.61025.0) and AjaxControlToolkit March 07 (1.0.10301.0). As you can imagine, we had to "tweak" a fair amount of code but in short, all is now working minus one major point.


We have a middle-tier DataAccessLayer that simply uses Microsoft's XSD's to connect to Oracle 9i and we make use of the Optimistic Concurrency feature. The front-end web with FormViews and Cascading dropdowns consumes the ObjectDataSource and works great on Insert and Update. But Deletes fail due to optimistic concurrency. It seems that only on deletes, the "Original_fieldname" values are NULL for any dropdown wired to a cascading control. However, "Original_fieldname" values are correct when UPDATE is clicked. Only when DELETE is clicked does the FormView fail to populate to original values and thereby the ObjectDataSource has NULL values as well.


Any ideas? Thanks!

Unfortunately, use of the CascadingDropDown isn't fully compatible with standard data-bound drop downs. The CascasdingDropDown expects to pick up it's data from the async web service call.

Off the top of my head, I'm not sure how those field values get populated, but I suspect it's part of the <%# Bind() %> functionality. The CascadingDropDown might be overwriting those values. You might be able to work around this by trapping the delete and filling in the value before the command is sent to the ObjectDataSource.


Thanks for the info. We used your suggestion in the ObjectDataSource_Deleting event and supplied all of the "original_xxx" InputParameters with values from a lookup to the record in question. Kind of a hack and somewhat defeats the purpose of optimistic concurrency, but it will do for now. Aside from that, the work your team has done on the toolkit is amazing. Keep it up!

CascadingDropDown works locally but not in production :(

I have a webcontrol that has a cascading drop down on it. It works great locally and it even works on one site on the production box but on another site it's not working at all.

When i view the soure locally, the bottom of the page has this:


<script type="text/javascript">
<!--
Sys.Application.queueScriptReference('/ScriptResource.axd?d=l8kme79LK37kNlRrAwkn4PmL8-xStSVBSrJo-1R7TM1iwaoCqJ1vwb4J4WezGvqzcUVV2DXtyW0_vdYX2osULzIIpv4c1X8ugso_D_opuH_NgNvFbZCQpZuDNYA5QZiu0&t=632999597834800200');
Sys.Application.queueScriptReference('/ScriptResource.axd?d=l8kme79LK37kNlRrAwkn4PmL8-xStSVBSrJo-1R7TM1iwaoCqJ1vwb4J4WezGvqzcUVV2DXtyW0_vdYX2osULzJI-iPrGdhwBb_ttd4JLeZNXWsInBtmjFBOo2HjJO4T0&t=632999597834800200');
Sys.Application.queueScriptReference('/ScriptResource.axd?d=l8kme79LK37kNlRrAwkn4PmL8-xStSVBSrJo-1R7TM1iwaoCqJ1vwb4J4WezGvqzcUVV2DXtyW0_vdYX2osULxwEztykssfzEPaqC7e0w3GSj3I_ajLJJSZPUOiWBO-4WX5KGuOIsKnZ6bBD0-vgFw2&t=632999597834800200');
Sys.Application.queueScriptReference('/ScriptResource.axd?d=l8kme79LK37kNlRrAwkn4PmL8-xStSVBSrJo-1R7TM1iwaoCqJ1vwb4J4WezGvqzcUVV2DXtyW0_vdYX2osUL8XSATuKv5sfFg9o9Zcf0duyde9-TL64IHjvO6rQEiff0xK_M6hS6brl95FcYskfAIaBT0vTReXwWC6ZPyjzBVA1&t=632999597834800200');
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.CascadingDropDownBehavior, [SNIP]);
});
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.CascadingDropDownBehavior, [SNIP]);
});
Sys.Application.initialize();
// -->
</script>
 
but when i view the source from production, that's completely missing. Anyone run into something like this before? 
 
BTW: this is on beta 2 and v.1.0.61106.0 of the toolkit. 

I was able to solve this myself by digging deeper.

there was a multiview on the page and the scriptmanager was in one of the views but not the others so no errors were thrown but the scriptmanager wasn't rendering the javascript.

Cascadingdropdown working with web methods

Hi,

I am using the Cascadingdropdown as below

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

<atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList1"Category="Principal"PromptText="Please select Principal"LoadingText="[Loading Principals...]"ServiceMethod="GetDropDownContentsPageMethod"/>

<atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList2"Category="MessageType"PromptText="Please select message type"LoadingText="[Loading Message Types...]"ServicePath=""ServiceMethod="GetDropDownContents1"ParentControlID="DropDownList1"/>

</atlasToolkit:CascadingDropDown>

<asp:DropDownListID="DropDownList1"runat="server">

</asp:DropDownList>

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

And the code behind is

<WebMethod()> _

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

Dim lobjDALAs VOSS.Integrations.Web.DataAccess.XmlAdmin

Try

lobjDAL =New VOSS.Integrations.Web.DataAccess.XmlAdmin

Return lobjDAL.GetRegions(knownCategoryValues, category)

Catch exAs Exception

ReturnNothing

Finally

lobjDAL =Nothing

EndTry

EndFunction

<WebMethod()> _

PublicFunction GetDropDownContents1(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AtlasControlToolkit.CascadingDropDownNameValue()

Dim lobjDALAs VOSS.Integrations.Web.DataAccess.XmlAdmin

Try

lobjDAL =New VOSS.Integrations.Web.DataAccess.XmlAdmin

Return lobjDAL.GetDropDownContents2(knownCategoryValues, category)

Catch exAs Exception

ReturnNothing

Finally

lobjDAL =Nothing

EndTry

ReturnNothing

EndFunction

Now the first function works and retrieves the values, but the second function does not. I am not using a web service. Do I need to always use a webservice for this. Can both the methods not pick values directly from db?

Pleae assist

Regards

Raj

Hi Raj,

You should check outFAQ Item #20.

Thanks,
Ted

CascadingDropDown Work only locally

HI,

I basically followed the sample toolkitCascadingdropdown. i only need 2 dropdown lists - Country and State.

everything works find on both local and live server. but when I'm calling the webservice from another website it has problems - a javascript error

<asp:DropDownList ID="ddlCountry" runat="server" />
<asp:DropDownList ID="ddlState" runat="server" />

<ajaxtoolkit:cascadingdropdown id="CascadingDropDown1" runat="server" category="State" loadingtext="Please wait..." parentcontrolid="ddlCountry" prompttext="Select a country"
servicemethod="GetStatByCountryID" servicepath="http://www.domainname.com/WebService/AddressService.asmx" targetcontrolid="ddlState">
</ajaxtoolkit:cascadingdropdown>

all sample I've seen is for working locally - both dropdownlists and webservice are sitting in the same website.

wondering if anyone can show me show to implement this cascadingdropdown by calling an external webservice

much appreciated

Hi,

So your intention is to call a external web service?

XmlHttpRequest object can't access external web service directly for security reasons. So, you may achieve this by adding a web service in the same domain, and this web service calls the external service. On client side, use this new web service to access the external web service indirectly.

Hope this helps.


This is exactly what I did, works out perfectly.

I created a local webserivce calling the external one.

much appreciated for your reply.

CascadingDropDown without WebServices

one of the new thing in the new release is that:

"CascadingDropDown can now call PageMethod as well as web services (Just leave the ServicePath property blank)"

is it possible to add an example so I can start, please...

I have all in a Class, and it work fine but I wonder if I can do this without postback's

http://portal.filterqueen.dk/

the country dd is populate from a Class function called
getAllCountries( ByVal dd as DropDownList )

the Offices are populate almost the same
getAllOfficesFromCountry( ByVal dd as DropDownList, ByVal country as String )

How can I ask for this functions and send it the parameters in the new CascadingDropDown?

Hi Bruno,

The newest version of the Toolkit includes an example of doing this in the CascadingDropDown.aspx file of the sample website. You'll notice that there are three Cascading DropDowns on the page and the first calls a page method while the second two call a webservice.

Thanks,
Ted

CascadingDropDown without PromptText - possible?

I put together a simple demo with two lists, and everything works fine when they both have the PromptText property set. When I leave the PromptText property empty on the parent list, it doesn't work - the parent list is disabled, and the user can't change the selection.

Since I always have a default selection for the parent list, I don't want the PromptText property to be set. Am I missing something?

Hi tomers,

In your case , if you set PromptText property to be empty, please set LoadingText property to be empty too. Just like below:

<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="dlState"
Category="State" ServicePath="../WebService/CityServiceOledb.asmx" ServiceMethod="GetStates">

Here is the source code section of CascadingDropDown(from line 170 to 272),which indicates why it is disabled:

_setOptions : function(list, inInit, gettingList) {
/// <summary>
/// Set the contents of the DropDownList to the specified list
/// </summary>
/// <param name="list" mayBeNull="true" elementType="Object">
/// Array of options (where each option has name and value properties)
/// </param>
/// <param name="inInit" type="Boolean" optional="true">
/// Whether this is being called from the initialize method
/// </param>
/// <param name="gettingList" type="Boolean" optional="true">
/// Whether we are fetching the list of options from the web service
/// </param>
/// <returns />

if (!this.get_isInitialized()) {
return;
}

var e = this.get_element();
// Remove existing contents
this._clearItems();

// Populate prompt text (if available)
var headerText;
if (gettingList && this._loadingText) {
headerText = this._loadingText;
} else if (this._promptText) {
headerText = this._promptText;
}
if (headerText) {
var optionElement = new Option(headerText, "");
e.options[e.options.length] = optionElement;
}

// Add each item to the DropDownList, selecting the previously selected item
var selectedValueOption = null;
var defaultIndex = -1;

if (list) {
for (i = 0 ; i < list.length ; i++) {
var listItemName = list[i].name;
var listItemValue = list[i].value;

if (list[i].isDefaultValue) {
defaultIndex = i;
if (this._promptText) {
// bump the index if there's a prompt item in the list.
//
defaultIndex++;
}
}

var optionElement = new Option(listItemName, listItemValue);
if (listItemValue == this._selectedValue) {
selectedValueOption = optionElement;
}

e.options[e.options.length] = optionElement;
}
if (selectedValueOption) {
selectedValueOption.selected = true;
}
}

// if we didn't match the selected value, and we found a default
// item, select that one.
//
if (selectedValueOption) {
// Call set_SelectedValue to store the text as well
this.set_SelectedValue(e.options[e.selectedIndex].value, e.options[e.selectedIndex].text);
} else if (!selectedValueOption && defaultIndex != -1) {
e.options[defaultIndex].selected = true;
this.set_SelectedValue(e.options[defaultIndex].value, e.options[defaultIndex].text);
} else if (!inInit && !selectedValueOption && !gettingList) {
this.set_SelectedValue('', '');
}

if (e.childDropDown && !gettingList) {
for(i = 0; i < e.childDropDown.length; i++) {
e.childDropDown[i]._onParentChange();
}
}
else {
if (list && (Sys.Browser.agent !== Sys.Browser.Safari) && (Sys.Browser.agent !== Sys.Browser.Opera)) {
// Fire the onchange event for the control to notify any listeners of the change
if (document.createEvent) {
var onchangeEvent = document.createEvent('HTMLEvents');
onchangeEvent.initEvent('change', true, false);
this.get_element().dispatchEvent(onchangeEvent);
} else if( document.createEventObject ) {
this.get_element().fireEvent('onchange');
}
}
}

// Disable the control if prompt text is present and an empty list was populated
if (headerText) {
e.disabled = !list || (0 == list.length);
}

this.raisePopulated(Sys.EventArgs.Empty);
},

For more details , you can press F11(by default) to debug your application step-by-step or add break points by using ScriptExplorer.

Hope it helps. If I misunderstood you , please let me know.


I'll chec that out. Is there any reason for this limitation? Why can't I have a LoadingText without a PromptText?

Thanks!


Hi tomers,

Has your problem been resovled yet?

tomers:

Is there any reason for this limitation? Why can't I have a LoadingText without a PromptText?

So far I haven't find any documents to explain this issue.Based on my research, I think the reason is that PromptText property is recommended not to set to empty by design pattern. We emptied the LoadingText and PromptText properties, it will made DropDownList.disable = false.

For more details, we can add break points into the source code and debug it step-by-step.

CascadingDropDown within an Accordion

I have a functioning CDD that I add dynamically to the page during ON_LOAD. I also have a new Accordion that I declare in the ASCX file. Both of these work fine until I try to put the CDD inside the Accordion. I get the following error:

Couldn't get extender properties on extender . Make sure the ID is spelled correctly and the control is on the page.

With the CDD inside the Accordion, I find the dropdown id using:

tempControl = MyAccordion.FindControl("ddlClientCompany")

item1.TargetControlID = tempControl.UniqueID

When I step thru the code with VS I can see that the control is found and an ID is passed in. But an error is thrown:o my question is: 1) is this a bug? 2) What is the correct procedure to include a CDD within the Accordion?

Here is my full code for when I add the CDD (this works fine outside of the Accordion)...

Dim tempExtenderAs AtlasControlToolkit.CascadingDropDown =New AtlasControlToolkit.CascadingDropDown()

Dim item1As AtlasControlToolkit.CascadingDropDownProperties =New AtlasControlToolkit.CascadingDropDownProperties()

item1.Category ="clientCompanyID"

If item1.Category =""Then item1.Category ="none"

item1.DefaultCompany = bu.default_company_id

item1.PromptText ="-- Select Company --"

item1.ServiceMethod ="GetClientCompanies"

item1.ServicePath ="~/buService.asmx"

Dim tempControlAs DropDownList

tempControl = MyAccordion.FindControl("ddlClientCompany")

item1.TargetControlID = tempControl.UniqueID

tempExtender.TargetProperties.Add(item1)

I'll defer to Ted as Accordion expert, but I'm thinking you don't want UniqueID in "item1.TargetControlID = tempControl.UniqueID". I'd try just ID instead.

Thanks for your reply David,

First let me say that I think Atlas rocks and and glad to be part of the CTP, pain and all. Secondly, I am very excited about how Atlas has effect my application interface design- cool ideas with low overhead to implement...nice job!

I did try some combinations that included the ID instead of the UniqueID...but they didnt work.

Although I never got it to work by adding the Extender dynamically, I was able to get it to work when I fully declared the CDD within the ASCX page. This is a work around in my mind and would be very interested in finding out how to do this properly dynamically.

I am also unable to get the SELECTED_VALUE of the CDD from within the Accordion. I am forced to just parse the query object like so.

' lets try to checkout the form values manually

Dim tempDDLClientCompanyAs DropDownList = MyAccordion.FindControl("ddlClientCompany")

Dim tempDDLClientNameAs DropDownList = MyAccordion.FindControl("ddlClientName")

' This is still not returning a value

'client_name = sec.ScrubData(tempDDLClientCompany.SelectedValue)

'manager_name = sec.ScrubData(tempDDLClientName.SelectedValue)

Dim tempClientCompanyID = tempDDLClientCompany.UniqueID

Dim tempClientNameID = tempDDLClientName.UniqueID

Try

Dim formsCountAsInteger = (Request.Form.Count) - 1

If formsCount <= 0ThenExitTry

Dim countAsInteger = 0

' 1) Grab the values from the request for company and client name

Dim tempField, tempValueAsString

' This is not zero based because the forms collection is not zero based.

For count = 1To formsCount

tempValue =CType(Request.Form.Item(count),String)

tempField =CType(Request.Form.GetKey(count),String)

If tempField = tempClientCompanyIDThen

client_name = tempValue

EndIf

If tempField = tempClientNameIDThen

manager_name = tempValue

EndIf

Next

Catch exAs Exception

EndTry


Hi Matthew,

Are you adding the extender right next to the drop down? If they're in different naming containers than that might explain why it can't find it (i.e. even though you pass in UniqueID, it still wouldn't be able to find a match if it was only looking in its own naming container).

Thanks,
Ted


Thanks for the reply Ted,

Let me try to recall that issue...it was a day or so ago and I have since gotten my head around other items, but I believe I tried several places for the extender. 1) Outside the Accordion, and 2) inside the Accordion within the same pane as the CDD if that is what you mean. I'll pull the code tomorrow and see where I left off. cheers,