ラベル dropdowns の投稿を表示しています。 すべての投稿を表示
ラベル dropdowns の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Reset Cascading Dropdown

I have a set of cascading dropdowns that I need to be able to programatically reset via javascript. I can change the selectedIndexes but that doesn't change any of the data "behind the scenes".

Thanks

Hi

Doesn't change any of the data "behind the scenes", What you mean?

Would you please post some code,so I can reproduce the problem and resolve it more quickly?

Thanks


As I have seen it for three cascading drop downs there are also three hidden form fields that contain data. My specific scenario was modifing some existing code that utilized three drop downs. The application was a store selector. The user could type in a postal code or use drop downs (Country, Region, City). I needed to reset the drop downs if a user types in a postal code. Setting up the blur event on the postal code text box was simple enough. But getting the drop-downs to reset was more challenging. I originally trimmed the item list down to the first item (please select). However on postback the original drop down selections came back. What I ended up doing was triming the item list and resetting the "hidden" fields to ":::" which is what the starting state appears to be.

There has to be an easier way to reset the drop downs to thier default state (via javascript). If the user simply sets the first drop down to the 0 index all drop downs reset. However, using using JS to set the selectedIndex property doesn't cause the client side event to fire.

Hopefully that helps a little. I am probably just missing something obvious. Is the client side JS code documented anywhere?

2012年3月26日月曜日

Retaining ViewState in Atlas

On my real estate website I have a Search page and a Results page. The Search page contains three linked Atlas cascading dropdowns (CDDs). The user makes some selections on these and then clicks a <search> button to see the results. This opens the Results page, which displays a list of properties meeting the search criteria. I have this working fine, apart from one thing: when the user goes back to the Search page, the CDDs have been reset to their original values. I was wondering if there was an easy way for the Search page to retain its settings. I have a partial solution, but it's not very good. If I set AutoPostBack to "True" for each CDD, they retain their settings when I click the <back> button on the browser. This is pretty horrible though, as it means the whole page gets posted back - undermining the whole purpose of using Atlas in the first place! I have tried enclosing the CDDs in an UpdatePanel (so that only they get posted back and not the whole page), but they just end up flickering all the time as (I guess) they get stuck in a code loop.

Also, setting AutoPostBack to "True" is only effective when the user clicks the browser's <back> button. I want to offer my own button or link in case they arrived at the Results page from another route. I have tried creating a hyperlink to the Search page, adding a button with a PostBackUrl of "Search.aspx" and adding a Response.Redirect command to a button's on_click event. Even with AutoPostBack set to "True" (which I want to avoid), none of these methods works. The CDDs just get reset every time.

Also, the other server controls I have on the Search page (check boxes, conventional drop-down list boxes, etc.) get reset every time too. I've tried looking into ViewState, but I can't get it to work. It looks like I need a way to save the viewstate on exit and somehow retrieve it when I load the page again. I guess I'm missing something fundamental. Any suggestions? Am I barking up the wrong tree? I imagine this kind of thing must have been done many times before and would appreciate a few hints.Any ideas on this? I'd really appreciate some help on something that must be a fairly common problem - or will be as Atlas takes off. Thanks for your interest.

You could try saving the viewstate to sessionstate or to disk

An example of saving viewstate to disk can be found here :
http://aspalliance.com/911


That seems to be on the right track. I'm now saving the values of my page controls to Session State when I exit the page, and retrieving them when I load it. This works fine for all the controls except the CDDs. Since these are populated by WebMethods, I don't seem to have any opportunity to set their SelectedValue properties. To focus on the problem area, I have tried adding a button to my form with a single line of code reading:ddlRegion.SelectedValue = RegionIDWhere RegionID is a value retrieved from the session.This causes an argument out of range exception as follows:[ArgumentOutOfRangeException: 'ddlRegion' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value]I get the same error if I change the variable RegionID to the literal "1" (which is definitely in the list).What it boils down to is this:How can I programatically set the SelectedValue of an Atlas Cascading Dropdown?I know how to save the value to, and retrieve it from, session state, but I don't know how to assign it to an Atlas cascading dropdown list. Any ideas?

1. Perest the CCD by setting the selected value of the cascading extender control ( and not the drop-down) , as explained in the article ( link )

2. and you can retrieve the viewsate ... as explained on this link.http://gandhirohan.blogspot.com/2007/09/cascadingdropdown-control.html

2012年3月24日土曜日

Root of Cascading Dropdowns Needs a Parameter. How do I do this?

I have a page with a dropdown called ddlYourTeams that is populated based on a single parameter, intUserID. If I don't cascade, I can populate this ddl with a SQL datasource that takes the intUserID parameter from a Session variable. I would like to make it the parent of two other dropdowns, ddlOpponents and ddlHomeFacilities. ddlOpponents would in turn be the parent of a fourth dropdown, ddlAwayFacilities. Each dropdown would have its corresponding Cascading Extender (CE). My problem is how to pass intUserID to the first webservice to get things going.

I thought of adding a parameter to the parent web service. But I believe this cannot be done as the CE's expect a fixed signature. Also I can't add a parameter because I can't access the point where it's invoked and so cannot set the parameter value.

In the context of the make-model-color example, I need to have the controls read a subset of makes from a ManufacturerID stored in session. So makes should be just GM makes, not all makes based on an external parameter.

How can I do this?

Thanks in advance for any assistance.

Hi,

You can append a parameter named contextKey to the webmethod.

For instance:

public static AjaxControlToolkit.CascadingDropDownNameValue[]
GetDropDownContentsPageMethod(string knownCategoryValues, string category, string contextKey)


CascadingDropDown2.ContextKey = "contextKeyOf2"; // this line set the value of the contextKey parameter


Raymond,

Thank you for your answer. Unfortunately, I was unable to get the suggestion to work. As this question is probably of interest to others as well, I wonder if you could upload a little example showing how to use the parameter.

I keep getting the error: 'AjaxControlToolkit.CascadingDropDown' does not contain a definition for 'ContextKey'

Thanks,

Jeff


Jeff,

Which version of Toolkit are you using? Can you update to the latest one and try again?


Another tip, session can be accessed from web service too. Please refer to this documentation: http://msdn2.microsoft.com/en-us/library/aa480509.aspx


And here is a sample make use of ContextKey.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { CascadingDropDown1.ContextKey = "contextKeyOf1"; CascadingDropDown2.ContextKey = "contextKeyOf2"; CascadingDropDown3.ContextKey = "contextKeyOf3"; } [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public static AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContentsPageMethod(string knownCategoryValues, string category, string contextKey) { AjaxControlToolkit.CascadingDropDownNameValue[] result = new AjaxControlToolkit.CascadingDropDownNameValue[10]; for (int i = 0; i < 10; i++) { result[i] = new AjaxControlToolkit.CascadingDropDownNameValue(); result[i].name = contextKey + i.ToString(); result[i].value = contextKey + i.ToString(); } return result; }</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"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true" /> <asp:DropDownList ID="DropDownList1" runat="server" > </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server"> </asp:DropDownList> <asp:DropDownList ID="DropDownList3" runat="server" > </asp:DropDownList> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" BehaviorID="cdd1" ServiceMethod="GetDropDownContentsPageMethod" Category="ca1" runat="server" PromptText="Please select a make" TargetControlID="DropDownList1"> </ajaxToolkit:CascadingDropDown> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" ServiceMethod="GetDropDownContentsPageMethod" Category="ca2" BehaviorID="cdd2" ParentControlID="DropDownList1" PromptText="Please select a make" runat="server" TargetControlID="DropDownList2"> </ajaxToolkit:CascadingDropDown> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" ServiceMethod="GetDropDownContentsPageMethod" Category="ca3" BehaviorID="cdd3" ParentControlID="DropDownList2" PromptText="Please select a make" runat="server" TargetControlID="DropDownList3"> </ajaxToolkit:CascadingDropDown> </div> </form></body></html>

I had been using 10201, which seems about 4 versions back. I have downloaded 10920 and will re-try your suggestion. Thanks again.