Showing posts with label value. Show all posts
Showing posts with label value. Show all posts

Monday, March 26, 2012

Preselecting a value in the CascadingDropDown control

G'day,

I have a form that saves and loads data from a database. Creating new forms is fine however when reloading hthe form for editing I want the CascadingDropDown control to have its previously selected value displayed.

I have tried the obvious such as loading the controls data and using SelectedValue = someId but it didn't work (probably not surprising!). I also tried setting the controls Text property incase Atlas detected a non empty value and left it alone. I had a bit of a look at the source but I don't yet know enough about the architecture to answer the question myself or to write some code.

Is there a way in this version of preselecting a value when setting up a form from server data on an initial page load?

Keep up the good work guys!

Regards,
Steven.

If you put the following code into the Page_Load for the CascadingDropDown.aspx, it will initialized the first item:

CascadingDropDown1.TargetProperties[0].ClientState ="BMW (value)";

Unfortunately you can't do this for other ones because the change of the first item to the specified value will clear the subsequent items, so we'll need to make improvements here.

But in general the idea is that you should be able to set the ClientState to be the string version of thevalue you want to set (not the text label).

Thinking more about this I think there's a few things we'll do in a future release (might not make our next refresh):

1) Add a strongly typed property for this e.g. "Selected" value

2) Try to make it so the value doesn't flash before the text gets set

3) Make sure you can do more than just the top level here.

Thanks for pointing this out, it's good feedback.

Thanks,

Shawn


So, am I to understand that currently values cannot be selected in dependent lists based on data that that was retrieved from a database?

When I user selects an item to edit, I populate the form with all the existing data for that item, however, some of my dependent lists are not getting the SelectedValue set.

I have an Account list (the parent), I am able to set its SelectedValue.

Sub-Account, Contact, Network and Gateway are dependent on Account. Gateway Version is dependent on Gateway.

When I populate my form the SelectedValue is set successfully for the following lists:

Account, Gateway, Gateway Version

The other lists are disabled and show the PromptText. This would be less confusing to me if ALL dependent lists were disabled with the prompt text selected.

Is there a way to make this work? Or do I need to abandon the CascadingDropDown and find another solution?

(My original post:http://forums.asp.net/thread/1383830.aspx)


It sounds like you have a 1:many parent:child relationship going on here. If so, then I think I fixed the problem withwork item 1704. Please trya recent development release and let us know if it's still not working.

(My app is a ticketing system)

I downloaded the Wed, 30 Aug 2006 17:53:43 GMT version and it solved my issue with the values of the "child" lists not getting selected when viewing/editing an existing ticket. However, now when I go to add a new ticket, my page hangs when it loads the CascadingDropDowns. My cursor becomes an hour glass and my browser becomes unresponsive. My lists never get populated, not even the "parent".

Eventually I get this error: "A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"

I'll download a different development release while I wait for a response and see if that makes a difference.

(Side note: I was going to upload a screen shot of the error, but I don't have permission to perform uploads.)


It sounds like either you have a circular reference in your page - or CascadingDropDown is adding one. :) If nothing stands out for you, please post a simple sample so we can have a look. Thanks!

If I add the CascadingDropDownProperties like this (below) the "Add New Ticket" pages hangs on load. However, the "Edit Existing Ticket" page will load/populate just fine - including all of the "child" lists.

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="AccountList"

Category="Account"

PromptText="-- Select Account --"

ServiceMethod="GetAccountList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="ExchangeList"

PromptText="-- Select Exchange --"

Category="Exchange"

ServiceMethod="GetExchangeList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="ContactList"

ParentControlID="AccountList"

PromptText="-- Select Contact --"

Category="Contact"

ServiceMethod="GetContactList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="SubAccountList"

ParentControlID="AccountList"

PromptText="-- Select Sub-Account --"

Category="SubAccount"

ServiceMethod="GetSubAccountList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="NetworkList"

ParentControlID="AccountList"

PromptText="-- Select Network --"

Category="Network"

ServiceMethod="GetNetworkList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="GatewayList"

ParentControlID="AccountList"

PromptText="-- Select Gateway --"

Category="Gateway"

ServiceMethod="GetGatewayList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="GatewayVersionList"

ParentControlID="GatewayList"

PromptText="-- Select Gateway Version --"

Category="GatewayVersion"

ServiceMethod="GetGatewayVersionList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

____________________________________________________________________________________________________

If I add the CascadingDropDownProperties like this (below) the "Add New Ticket" page loads just fine, however, the "Edit Existing Ticket" page doesn't populate the "child" lists properly - only Account, Gateway, and GatewayVersion have the correct values selected.

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="AccountList"

Category="Account"

PromptText="-- Select Account --"

ServiceMethod="GetAccountList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="ExchangeList"

PromptText="-- Select Exchange --"

Category="Exchange"

ServiceMethod="GetExchangeList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="ContactList"

ParentControlID="AccountList"

PromptText="-- Select Contact --"

Category="Contact"

ServiceMethod="GetContactList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="SubAccountList"

ParentControlID="AccountList"

PromptText="-- Select Sub-Account --"

Category="SubAccount"

ServiceMethod="GetSubAccountList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="NetworkList"

ParentControlID="AccountList"

PromptText="-- Select Network --"

Category="Network"

ServiceMethod="GetNetworkList"

ServicePath="CascadingListService.asmx"/>

<atlasToolkit:CascadingDropDownProperties

TargetControlID="GatewayList"

ParentControlID="AccountList"

PromptText="-- Select Gateway --"

Category="Gateway"

ServiceMethod="GetGatewayList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>

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

<atlasToolkit:CascadingDropDownProperties

TargetControlID="GatewayVersionList"

ParentControlID="GatewayList"

PromptText="-- Select Gateway Version --"

Category="GatewayVersion"

ServiceMethod="GetGatewayVersionList"

ServicePath="CascadingListService.asmx"/>

</atlasToolkit:CascadingDropDown>


We'll probably need the corresponding web service (or one that returns close enough data to reproduce the problem), too, please. If this can be reproduced with the SampleWebSite's web service, a demonstration using that is also fine.

Saturday, March 24, 2012

Problem getting SelectedIndex from CascadingDropDown in an UpdatePanel

Hey everyone, I'm having an issue with my AJAX page. I have a CascadingDropDown that once a value is selected, trigger the population of another CascadingDropDown that resides in an UpdatePanel. I'm attempting to have the second CascadingDropDown populate a textbox based on its .SelectedIndex. For some reason, I can grab the .SelectedValue, but getting .SelectedIndex always returns 0.

Does anyone else have this problem, or know how to solve it. Any help would be greatly appreciated.

Did you find a solution for your problem? Coz I also have the same problem

hi,

please refer :http://ajax.asp.net/ajaxtoolkit/CascadingDropDown/CascadingDropDown.aspx

please post the code, so that i can help you to solve your problem.

Thanks

Kishore.

www.relgo.com


hello invisible man,

thanks for the reply, here is my scenario... i have two cascadingdropdown control on my page, and then I have a dynamicpopulate control (which is binded or the targetcontrol is a textbox) that is dependent on the selected value of the two cascadingdropdown control. The problem is passing the value of both the cascadeddropdown control to the dynamicpopulate control.

here is my aspx code (i did not include the master page)

123<%@.4Page Language="C#"5MasterPageFile="~/NOCMasterPage.master"6AutoEventWireup="true"7CodeFile="ApplicationForm.aspx.cs"8Inherits="ApplicationForm"9Title="Sharjah NOC Application Form"10EnableEventValidation="false" %>1112<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>1314"ApplicationFormContent" ContentPlaceHolderID="cphNOCMasterPage" Runat="Server">15 "smApplicationForm" runat="server">1617 "text/javascript">18 function SelectFromDDL(ddPlotNumberID, ddAreaNameID)19 {20 alert(document.getElementsByName(ddPlotNumberID));21 var e = document.getElementsByName(ddPlotNumberID);// get ddPlotNumber element22 alert(eval([e.selectedIndex].text));2324 }2526 function fnContextValue(strSelectedAreaNameSelectedPlotNo)27 {28 var behaviorId = $find('dpePlotAreaID');29if (behaviorId)30 {31 behaviorId.populate(strSelectedAreaNameSelectedPlotNo);32 }3334 }3536

3738 39 "lblAreaName" runat="server" Text="Area Name" Width="238px" Font-Names="Arial" ForeColor="MidnightBlue">40 "ddAreaName" runat="server" EnableViewState="false">4142 "cddAreaName" runat="server"43 PromptText="Please select the Area in Manhattan"44 LoadingText="Loading ...."45 TargetControlID="ddAreaName"46 ServicePath ="PlotAreaService.asmx"47 ServiceMethod ="GetAreaName"48 Category="AreaName">4950

51

52 53 "lblPlotNumber" runat="server" Text="Plot Number" Width="238px" Font-Names="Arial" ForeColor="MidnightBlue">54 55 "ddPlotNumber" runat="server">565758 "cddPlotNo" runat="server"59 TargetControlID="ddPlotNumber"60 ParentControlID="ddAreaName"61 PromptText="Please select Plot Number inside the selected Area"62 ServicePath ="PlotAreaService.asmx"63 ServiceMethod ="GetPlotNo" Category="PlotNo">6465

66

67 68 "lblPlotArea" runat="server" Text="Area of Plot" Width="238px" Font-Names="Arial" ForeColor="MidnightBlue">69 70 "txtPlotArea" runat="server" Width="205px">71 "dpePlotArea" runat="server"72 ServicePath="PlotAreaService.asmx"73 ServiceMethod="GetPlotArea"74 TargetControlID="txtPlotArea"75 ContextKey=""76 ClearContentsDuringUpdate="true"77 BehaviorID="dpePlotAreaID">787980

8182838485page code behind8687using System;88using System.Data;89using System.Configuration;90using System.Collections;91using System.Web;92using System.Web.Security;93using System.Web.UI;94using System.Web.UI.WebControls;95using System.Web.UI.WebControls.WebParts;96using System.Web.UI.HtmlControls;97using System.Data.OleDb;98using System.Data.SqlClient;99using System.Collections.Specialized;100using System.Workflow.Runtime;101using System.Workflow.Runtime.Hosting;102using AjaxControlToolkit;103104105public partialclass ApplicationForm : System.Web.UI.Page106// Use BasePage.cs as code file for parameter getting and107// access to Module.cs108//public partial class ApplicationForm : BasePage109{110protected void Page_Load(object sender, EventArgs e)111 {112113string strPlotNumberID ="ctl00_cphNOCMasterPage_cddPlotNo_ClientState";114//string strAreaNameID = cddAreaName.ID;115 // CascadingAreaName Id not the dropdown116string strAreaNameID ="ctl00_cphNOCMasterPage_cddAreaName_ClientState";117 ddPlotNumber.Attributes.Add("OnChange","return SelectFromDDL(" + strPlotNumberID +"," + strAreaNameID +" )");118 }119120121}122123124125web service code126127using System;128using System.Web;129using System.Collections;130using System.Collections.Specialized;131using System.Collections.Generic;132using System.Xml;133using System.Web.Services;134using System.Web.Services.Protocols;135using System.Data;136using System.Data.OleDb;137using System.Data.SqlClient;138using AjaxControlToolkit;139140/// <summary>141/// Summary description for PlotAreaService142/// </summary>143[WebService(Namespace ="http://tempuri.org/")]144[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]145[System.Web.Script.Services.ScriptService]146public class PlotAreaService : System.Web.Services.WebService147{148 string strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=****data table name ******;Data Source=*** Database Server Instance name****";149 string strTableName = "dbo.sharjah_area_name";150 string fldAreaName = "area_name";151 string fldPlotNo = "area_plot_number";152 string fldAreaOfPlot = "area_of_plot";153154public PlotAreaService()155 {156157//Uncomment the following line if using designed components158 //InitializeComponent();159 }160161162/*************************************163 * Required by cascading drop down164 * parameter name and type should not be changed165 * ***********************************/166 [WebMethod]167public CascadingDropDownNameValue[] GetAreaName(string knownCategoryValues,string category)168 {169170 dsAreaNameTableAdapters.sharjah_area_nameTableAdapter objAreaNameAdapter =new dsAreaNameTableAdapters.sharjah_area_nameTableAdapter();171 List lstAreaName =new List();172173foreach (DataRow drAreaNameTempin objAreaNameAdapter.dtGetDataAreaName())174 {175string strAreaName = drAreaNameTemp[fldAreaName].ToString();176 lstAreaName.Add(new CascadingDropDownNameValue(strAreaName, strAreaName));177178 }179180return lstAreaName.ToArray();181 }182183 [WebMethod]184public CascadingDropDownNameValue[] GetPlotNo(string knownCategoryValues,string category)185186 {187string[] arrChosenAreaName = knownCategoryValues.Split(':',';');188string strChosenAreaName = arrChosenAreaName[1];189 dsPlotNoTableAdapters.sharjah_area_nameTableAdapter objPlotNoAdapter =new dsPlotNoTableAdapters.sharjah_area_nameTableAdapter();190 List lstPlotNo =new List();191foreach (DataRow drPlotNoin objPlotNoAdapter.dtPlotNoData(strChosenAreaName))192 {193string strPlotNo = drPlotNo[fldPlotNo].ToString();194 lstPlotNo.Add(new CascadingDropDownNameValue(strPlotNo, strPlotNo));195196 }197return lstPlotNo.ToArray();198 }199200 [WebMethod]201public string GetPlotArea(string contextKey)202 {203 System.Threading.Thread.Sleep(250);204string strPlotArea =string.Empty;205string[] arrContextKey = contextKey.Split(',');206string strAreaName = arrContextKey[0];207string strPlotNo = arrContextKey[1];208 dsPlotAreaTableAdapters.sharjah_area_nameTableAdapter objPlotAreaAdapter =new dsPlotAreaTableAdapters.sharjah_area_nameTableAdapter();209210foreach (DataRow drPlotAreain objPlotAreaAdapter.dtPlotAreaData(strAreaName, strPlotNo))211 {212 strPlotArea = drPlotArea[fldAreaOfPlot].ToString();213 }214return strPlotArea;215 }216}217218219220