Showing posts with label dropdownlist. Show all posts
Showing posts with label dropdownlist. Show all posts

Saturday, March 24, 2012

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);

Wednesday, March 21, 2012

CascadingDropDown placed inside an asp:EditItemTemplate.

I tried the cascading dropdownlist when the user clicks on edit on a formview, but I realized from the following error that this will not work:

System.InvalidOperationException: The UpdatePanel 'EditUpdatePanel' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template.

I also found a previous threadhttp://forums.asp.net/thread/1255759.aspxwhere the respondent confirmed that the updatePanel must be outside of the GridView

Does that mean that theAtlasControlToolkit:cascadingdropdown control cannot be used within any databound templated controls (such as GridView, FormView, Details, etc.)?

I don't believe so. UpdatePanel has "special needs" on the page which is why it probably has this issue. I haven't tried this but I think CascadingDropdownshould work OK - I can't think of why it wouldn't. Can you give it a try and report back?


I think the problem is that theatlasToolkit:CascadingDropDown requires anatlas:UpdatePanel around the dropdownlists otherwise changing the selection in one dropdownlist would not affect the next. But sinceatlas:UpdatePanel cannot be placed within the EditItemTemplate therefore it seems that there is no way to put theatlasToolkit:CascadingDropDown within the EditItemTemplate.

Here I tried 3 scenarios in addition to the one I described in my previous post:

1- The cascadingdropdown lists work if placed within atlas:UpdatePanel outside of an EditItemTemplate:http://www.webswapp.com/codesamples/aspnet20/atlas/cascadingdropdown.aspx

2- The cascadingdropdown lists not working if placed within the EditItemTemplate and the atlas:UpdatePanel outside the FormView. http://www.webswapp.com/codesamples/aspnet20/atlas/cascadingdropdown2.aspx

(On my local PC, a JavaScript popup dialog box comes with the following error: "System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or in a page." But when run remotely you do not get that error. The lists just do not display anything)

3- The cascadingdropdown lists not working if placed within the EditItemTemplate and no atlas:UpdatePanel on the page

The source code for all scenario are listed on the demo pages.


CascadingDropDown does not need an UpdatePanel to work - the client-side changes are done in script and the web service requests are async thanks to Atlas. So #3 above is the scerario you probably want. I suspect it's not working for you because your ParentControlID properties are pointing at "CascadingDropDownX", but your DropDown controls are named "ddlYYY". Please try fixing that and let us know how it goes!

Hi David,

Thanks for your help. Your suspicion was right. I had the wrong values for the ParentControlID. Now that I corrected them and got it working within the FormView's EditItemTemplate and the data is being updated upon postback successfuly as shown here: http://www.webswapp.com/codesamples/aspnet20/atlas/toolkit_cascadingdropdown.aspx

I am wondering about the possibility of doing 2 more features to make the function of this control equivalent to the server-side controls:

1- How to set the default values upon loading the EditItemTemplate? (Since I could not use the Bind or Eval statements)

2- In order to prevent flashing of the screen when I submit the FormView, I tried using the Atlas:UpdatePanel around the FormView but I got this error message:

Assertion Failed: Unrecognized tag AtlasControlExtender:ValidationScript


That is so cool!

From above...

1) This is a feature we've added to the refresh, which should be available within the next day or so. When it is, you can just add a "SelectedValue='blah'" to the properties and it'll select that value

2) I'm not sure why you're getting that. In any case, in your extender set "SuppressValidationScript='false'" and it'll preven that guy from even loading.


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

I tried # 2 above but I still get the error. The code is exactly as listed in the link I provided before plus the updatePanel surrounding the FormView

<atlas:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:FormViewID="FormView1"runat="server" .... >

</asp:FormView>

</ContentTemplate>

</atlas:UpdatePanel>


SuppressValidationScript="true"

Ok. The first error (above) does not show up but the next errors (which used to appear after I clicked on cancel) is still repeated for each dropdown list: "Assertion Failed: Unrecognized tag atlasControlToolkit:cascadingDropDownBehavior"


That's often related to the relative position of the controls, the extender, and the UpdatePanel. Some wiggling around of the different items can sometimes solve the problem. If it doesn't - and if the new Toolkit release doesn't help - please let us know.

CascadingDropDown persistent Values

Hi,i have 3 dropdownlist, using atlas cascadingdropdown. Every think works fine, but when i click in a button( this button only set the enable=true to all control in the page) occurs an postback, then when the page is load the dropdown loser the previos selected values..

the method to populate the dropdown are in the if(!Ispostback)...how can i fix that??

Try setting the SelectedValue property of the CDDs in the button handler.

hi, thanks for the reply but i have already tryied that and dont work...

bye,

marcos


Please reply with acomplete, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

CascadingDropDown inside of a repeater

I'm trying to create a CascadingDropDown inside of a repeater, and just can't seem to figure it out.

I have a dropdownlist created within a repeater that should cascade from another dropdownlist that is also generated within the repeater.

The problem that arises from this situation is when I go to set the CascadingDropDownProperties, I get this error:

Object reference not set to an instance of an object.

Description:Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of thecurrent web request. Information regarding the origin and location ofthe exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
AtlasControlToolkit.CascadingDropDown.OnPreRender(EventArgs e) in d:\Depot\Atlas\agility\AtlasControls\MAIN\Src\ControlLibrary\CascadingDropDown\CascadingDropDownExtender.cs:60
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360


When I go through with the debugger it doesn't break on any line of code, so I'm not totally sure what's causing the error. I have figured out that the problem happens when I set the TargetControlID, because If I comment out that line then It'll work. I'm guessing I'll have the same problems with the ParentControlID, also.

cddpNew.TargetControlID = DropDownListControl.ClientID

Has anyone gotten a Cascading drop down to work within a repeater?Since that didn't work I decided to take another approach, which is to put the CascadingDropDown inside the repeater. This had it's own problem.

When trying to get the control from within the repeater during the function that handles the databinding event for the repeater I get the error:

Value of type 'System.Web.UI.Control cannot be converted to 'AtlasControlToolkit.CascadingDropDownProperties'.

So, no luck this direction either.Sad
In the first case, you probably need to access the CascadingDropDown through the Repeater container (recall that the Repeater creates many instances of its contents). The way ASP.NET implements repeaters is a little tricky, but I think you should be able to accomplish what you want with the right code.

CascadingDropDown in a datagrid

Hello,

Is it possible to populate a dropdownlist inside a datagrid, which will repeat itself for as many rows their are inside the datagrid? Any example code would be appreciated. Thanks.

Yes, I'd expect this to work. If you run into problems, please let us know!