private CascadeDropdownFieldControl GetParentCausedPostback()
        {
            if (!Page.IsPostBack)
            {
                return(null);
            }

            var controlPostback = Page.Request["__EVENTTARGET"];
            CascadeDropdownFieldControl        postbackControl = null;
            List <CascadeDropdownFieldControl> childControls   = new List <CascadeDropdownFieldControl>();

            //find post back caused by control
            foreach (var control in SPContext.Current.FormContext.FieldControlCollection)
            {
                if (control is CascadeDropdownFieldControl)
                {
                    if (((CascadeDropdownFieldControl)control).cascader.UniqueID == controlPostback)
                    {
                        postbackControl = control as CascadeDropdownFieldControl;
                        continue;
                    }

                    childControls.Add(control as CascadeDropdownFieldControl);
                }
            }

            if (postbackControl == null)
            {
                return(null);
            }
            if (this == postbackControl)
            {
                return(null);
            }

            return(postbackControl);
        }
        private string GetParentValue()
        {
            if (parentField.CascadeType == "Parent")
            {
                return(null);
            }

            foreach (var field in SPContext.Current.FormContext.FieldControlCollection)
            {
                if (field is CascadeDropdownFieldControl)
                {
                    CascadeDropdownFieldControl cdfField = field as CascadeDropdownFieldControl;

                    if (cdfField.FieldName == parentField.CascadeParent)
                    {
                        if (cdfField.cascader != null)
                        {
                            //bool parentChanged = DidParentChange();
                            CascadeDropdownFieldControl parentPostbackControl = GetParentCausedPostback();

                            if (Page.IsPostBack && parentPostbackControl != null && parentPostbackControl.FieldName == parentField.CascadeParent)
                            {
                                var headerData = Page.Request[cdfField.cascader.UniqueID];
                                if (!String.IsNullOrEmpty(headerData))
                                {
                                    return(headerData);
                                }
                            }

                            return(cdfField.cascader.SelectedValue);
                        }
                    }
                }
            }

            return(null);
        }
        private bool DidParentChange()
        {
            if (!Page.IsPostBack)
            {
                return(false);
            }

            var controlPostback = Page.Request["__EVENTTARGET"];
            CascadeDropdownFieldControl        postbackControl = null;
            List <CascadeDropdownFieldControl> childControls   = new List <CascadeDropdownFieldControl>();

            //find post back caused by control
            foreach (var control in SPContext.Current.FormContext.FieldControlCollection)
            {
                if (control is CascadeDropdownFieldControl)
                {
                    if (((CascadeDropdownFieldControl)control).cascader.UniqueID == controlPostback)
                    {
                        postbackControl = control as CascadeDropdownFieldControl;
                        continue;
                    }

                    childControls.Add(control as CascadeDropdownFieldControl);
                }
            }

            if (postbackControl == null)
            {
                return(false);
            }
            if (this == postbackControl)
            {
                return(false);
            }

            if (childControls.Count > 0)
            {
                var control = childControls[0];

                while (control != null)
                {
                    if (control.parentField.CascadeParent == postbackControl.FieldName)
                    {
                        return(true);
                    }

                    //find controls parent control and check
                    CascadeDropdownFieldControl tempControl = null;
                    for (int x = 0; x < childControls.Count; x++)
                    {
                        if (control.parentField.CascadeParent == childControls[x].FieldName)
                        {
                            tempControl = childControls[x];
                            break;
                        }
                    }

                    if (tempControl != control)
                    {
                        control = tempControl;
                    }
                }
            }

            return(false);
        }