CascadingDropdown: child dropdown shows old value after postback (IE only)

Jul 5, 2012 at 2:56 PM

Hi,

we use the cascading dropdown on an edit form with an additional quicksave that saves the data but keeps the form opened.

After the postback the value shown in the child dropdown is set to the former value. The new value is shown for a short time, before it is set to the old value. I guess, getDropDownSelected returns the wrong value.

The strange thing is, that after another postback the value is set.

In Firefox everything works fine.

Do you have any suggestion on where to start finding the issue? Thank you,

Phil

Coordinator
Jul 6, 2012 at 6:41 PM

Phil:

I don't know what you mean by "an additional quicksave". Is this some other jQuery plugin? If so, my guess is that it is interfering with SPServices somehow.

M.

Aug 1, 2012 at 10:21 AM

Hi Marc,

by now we have a webpart on the edit form showing the list fields. We have the SharePoint 'Save' and 'Cancel' buttons plus an addional 'QuickSave' button that is supposed to save the list item but does not close the dialog window:

                #region Create toolbar
                QuickSave.Click += OnClickQuickSave;
                if (ItemFound)
                {
                    ToolBarTbl.AddToolBarInfo(SPControlMode.Edit);
                    var buttons = new List<Button> { QuickSave };
                    ToolBarTbl.AddToolBarButtons(SPControlMode.Edit, true, buttons);
                }
                #endregion

    <wssuc:ToolBar CssClass="ms-formtoolbar" id="ToolBarTbl" RightButtonSeparator="&nbsp;" runat="server" style="padding:20px;">
    </wssuc:ToolBar>

Up to the server side this works fine. The item is stored and the page is opened again. But the information in the child dropdown still shows the data the item had before saving.

In detail we have one combobox for the 'category' and one for a 'subcategory'. Let's assume, we currently have the category '1' and the subcategory '1.1'. Then we edit the item changing the subcategory to '1.2'. We hit the button for 'QuickSave' doing a postback and saving the list item (code given below). The item is stored correctly with the new data (as can be verified in a new browser window). But the edit form only shorty shows the correct value (with the complex dropdown). When showing the simple dropdown the correct value is replaced by the old one.

 

 

        protected void OnClickQuickSave(object sender, EventArgs e)
        {
            SPListItem li = null;
            SPWeb currentWeb = SPContext.Current.Web;

            List<BaseFieldControl> ctls = FindControls<BaseFieldControl>(ContentAllgemein);
            ctls.AddRange(FindControls<BaseFieldControl>(ContentAufwand));
            ctls.AddRange(FindControls<BaseFieldControl>(ContentDiverse));
            ctls.AddRange(FindControls<BaseFieldControl>(ContentWeitere));

            var displayOnlyFields = new StringCollection();
            if (true)
            {
                //var listId = SPEncode.UrlDecodeAsUrl(Request.Params["List"]);
                SPList list = SPContext.Current.List;

                switch (list.RootFolder.Name)
                {
                    case "Anforderungen GOB":
                        displayOnlyFields = currentWeb.GetPropertyBagValues("displayonlyfieldsanf");
                        break;
                    case "Anforderungen":
                        displayOnlyFields = currentWeb.GetPropertyBagValues("displayonlyfieldsanf");
                        break;
                    case "Spezifikationen GOB":
                        displayOnlyFields = currentWeb.GetPropertyBagValues("displayonlyfieldsspezi");
                        break;
                    case "Spezifikationen":
                        displayOnlyFields = currentWeb.GetPropertyBagValues("displayonlyfieldsspezi");
                        break;
                }

                foreach (BaseFieldControl bfc in ctls)
                {
                    if (displayOnlyFields.Count == 0 || !displayOnlyFields[0].Contains(bfc.FieldName))
                    {
                        bfc.UpdateFieldValueInItem();
                        li = bfc.ListItem;
                    }
                }

                if (li != null)
                {
                    li.Update();
                }
            }
        }

Thank you.
Coordinator
Aug 1, 2012 at 3:52 PM

It's a little hard to follow what you are doing, but if the form is reloaded, then SPCascadeDropdowns should show the saved values. The function doesn't reread the values from the saved item; it relies on them being in the form to start with. The script simply filters the available options based on how you've configured things.

M.

Aug 2, 2012 at 1:03 PM

Hi Marc,

I did some more research... and found the solution to this. It has nothing to do with SPServices :-) It seems that SharePoint does not like postbacks on editforms. We now do a postback with a redirect to the same page to enforce loading the page with all proper values anew.

Coordinator
Aug 2, 2012 at 2:43 PM

Great. I couldn't tell if that was what you were doing or not, but that should work.

M.