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

Wednesday, March 28, 2012

How do I set focus on CascadingDropDown?

I'm trying to set focus on a Dropdownlist that's being populated by the nice CascadingDropDown tool. But I can't. Everything else works great, The forms retreive, insert, update without page postbacks via updatepanel. The CascadingDropDown tools work well with the dropdownlists and it all populates dependent on each other and without page postbacks. BUT I can't seem to set the focus to the dropdownlist that's being populated by the CascadingDropDown tool..

I've got the scriptmanager on the masterpage and the Dropdownlist I want to set focus upon is in a formview. I want it to set focus on the control when the form is changed to a insert or edit mode.

So my code behind is like this:

protectedvoid formView1_ModeChanged(object sender,EventArgs e)

{

if (formView1.CurrentMode ==FormViewMode.Insert || formView1.CurrentMode ==FormViewMode.Edit)

{

Master.ScriptManager1.SetFocus(formView1.FindControl("ddl_iWantFocused"));

}

}

Works great for selecting any other control in the form, but not the one populated with the CascadingDropDown.

Any help on how to set focus on this?

Let me revise that. I can SetFocus on other DropDownLists that don't use the CascadingDropDownList extender, but haven't been able to SetFocus on a Textbox.

Monday, March 26, 2012

How do i clear/reset a cascadingdropdown?

i have three dropdownlists. once i've selected third i fire a postback using the third dropdown's autopostback property. my question is how do i get all the dropdowns to reset back to their prompt messages ready to be used again.

i've tried changing the selectedindexes for the dropdowns to 0 and -1 but that doesn't work

Check outthis thread.

isn't there an easier way of doing this? Seems like a lot of work just to reset the dropdownlists


Hi Iljones,

Based on my research, I think the best solution is to modify the source code to meet your expectation. Here is another sample, please add the code below to your source code. When the last CascadingDropDown populated , onpopulated function will be called and it will set the first CascadingDropDown's selectedIndex to be 0.

<script type="text/javascript" language="javascript">
var flag = true;
function pageLoad(sender, args){
$find("myCDECity").add_populated(onpopulated);
}
function onpopulated(sender,args){
if(flag){
flag = false;
$get("<%=dlState.ClientID%>").selectedIndex = 0;
$find("myCDECity")._onParentChange(false);
$get("<%=dlCity.ClientID%>").disabled = true;
}
}
</script>

Hope this help.

Best Regards,

Jonathan


Jonathan Shen – MSFT:

Hi Iljones,

Based on my research, I think the best solution is to modify the source code to meet your expectation. Here is another sample, please add the code below to your source code. When the last CascadingDropDown populated , onpopulated function will be called and it will set the first CascadingDropDown's selectedIndex to be 0.

<script type="text/javascript" language="javascript">
var flag = true;
function pageLoad(sender, args){
$find("myCDECity").add_populated(onpopulated);
}
function onpopulated(sender,args){
if(flag){
flag = false;
$get("<%=dlState.ClientID%>").selectedIndex = 0;
$find("myCDECity")._onParentChange(false);
$get("<%=dlCity.ClientID%>").disabled = true;
}
}
</script>

Hope this help.

Best Regards,

Jonathan

i'll give this a go today and let you know how it goes. Thanks Jonathan


Probarly to late, but here is an answer anyway.

CS: protected void Reset_Click(object sender, EventArgs e) { CascadingDropDown1.SelectedValue = null; }