public void InitializeWithField(SPField field)
        {
            using (new EnterExitLogger("CCSCascadedLookupFieldEditor:InitializeWithField function"))
            {
                try
                {
                    ErrorText.Visible = false;
                    _ccsCascadedField = field as CCSCascadedLookupField;
                    if (!IsPostBack)
                    {
                        PopulateAndSetValuesControls();

                        SetCheckboxcontrolsValue();

                        AddingNewFieldControlVisibility();

                        SetRelationShipControlsValue();

                        //if (field != null) ;
                    }
                }
                catch (Exception ex)
                {
                    Utils.LogManager.write("Exception Occurs in InitializeWithField Function. \r\nError Message: " + ex.Message + "\r\nStack Trace: " + ex.StackTrace, "error");
                    ShowErrorMessage(ex.Message);
                }
            }
        }
        void ConvertToSPFieldLookup(CCSCascadedLookupField field)
        {
            using (new EnterExitLogger("CCSCascadedLookupFieldEditor:ConvertToSPFieldLookup function"))
            {
                XmlDocument doc = new XmlDocument();
                Utils.LogManager.write("Before CCSCascadedLookupField xmlScema: " + field.SchemaXml);
                
                doc.LoadXml(field.SchemaXml);

                //Creating Attributes

                CreateAttribute(doc, "Type", "Lookup");

                DeleteAttribute(doc, "WebId");

                DeleteAttribute(doc, "SourceWebID");

                DeleteAttribute(doc, "LookupFieldListName");

                DeleteAttribute(doc, "LookupFieldName");

                DeleteAttribute(doc, "ParentLinkedColumnName");

                DeleteAttribute(doc, "AllowMultipleValues");

                DeleteAttribute(doc, "AdvancedSetting");

                DeleteAttribute(doc, "View");

                DeleteAttribute(doc, "LinkToParent");

                DeleteAttribute(doc, "ShowAllOnEmpty");

                DeleteAttribute(doc, "AllowNewEntry");

                DeleteAttribute(doc, "UseNewForm");

                DeleteAttribute(doc, "SortByView");

                DeleteAttribute(doc, "AllowAutocomplete");

                DeleteAttribute(doc, "AdditionalFields");

                DeleteAttribute(doc, "AdditionalFilters");


                doc.DocumentElement.InnerXml = "";


                field.SchemaXml = doc.OuterXml;
                Utils.LogManager.write("After CCSCascadedLookupField xmlScema: " + field.SchemaXml);
                
                field.Update();
            }
        }
示例#3
0
        public static void GetParametersValue(CCSCascadedLookupField field, out string WebUrl, out string LookupListName, out string FieldParentLinkedFieldName, out string FieldLookupFieldName, out string FieldViewWhereString, out string FieldViewOrderString)
        {
            using (new EnterExitLogger("Utilities:GetParametersValue function"))
            {
                WebUrl                     = "";
                LookupListName             = "";
                FieldParentLinkedFieldName = "";
                FieldLookupFieldName       = "";
                FieldViewWhereString       = "";
                FieldViewOrderString       = "";

                string webUrl                = "";
                string lookupListName        = "";
                string LookupFieldName       = "";
                string ParentLinkedFieldName = "";
                string ViewWhereString       = "";
                string ViewOrderString       = "";
                Utils.LogManager.write("Field : " + field.Title);
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                    {
                        SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];
                        webUrl            = LookupWeb.Url;
                        Utils.LogManager.write("webUrl : " + webUrl);

                        lookupListName = LookupList.Title;
                        Utils.LogManager.write("lookupListName : " + lookupListName);

                        LookupFieldName = field.LookupFieldName;
                        Utils.LogManager.write("LookupFieldName : " + LookupFieldName);


                        if (!string.IsNullOrEmpty(field.GetParentLinkedColumnId()))
                        {
                            //string linked_column = field.GetProperty(CustomDropDownList.LINK_COLUMN);
                            SPField ParentLinkedField = LookupList.Fields[new Guid(field.GetParentLinkedColumnId())];
                            if (ParentLinkedField != null)
                            {
                                ParentLinkedFieldName = ParentLinkedField.InternalName;
                                Utils.LogManager.write("ParentLinkedFieldName : " + ParentLinkedFieldName);
                            }
                        }

                        if (!string.IsNullOrEmpty(field.View))
                        {
                            SPView view = LookupList.GetView(new Guid(field.View));

                            if (!String.IsNullOrEmpty(view.Query))
                            {
                                string viewQueryXML         = string.Format("<Query>{0}</Query>", view.Query);
                                XmlDocument viewQueryXMLDoc = new XmlDocument();
                                viewQueryXMLDoc.LoadXml(viewQueryXML);
                                XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                {
                                    ViewWhereString = whereNode.InnerXml;
                                    Utils.LogManager.write("ViewWhereString : " + ViewWhereString);
                                }

                                XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                {
                                    ViewOrderString = orderByNode.InnerXml;
                                }

                                ViewOrderString = string.Format("<OrderBy>{0}</OrderBy>", ViewOrderString);
                                Utils.LogManager.write("ViewOrderString : " + ViewOrderString);
                            }
                        }
                    }
                });

                WebUrl                     = webUrl;
                LookupListName             = lookupListName;
                FieldParentLinkedFieldName = ParentLinkedFieldName;
                FieldLookupFieldName       = LookupFieldName;
                FieldViewWhereString       = ViewWhereString;
                FieldViewOrderString       = ViewOrderString;
            }
        }
示例#4
0
        public static void FetchAllValuesFromList(CCSCascadedLookupField field, ref List <ListItem> itemList)
        {
            using (new EnterExitLogger("Utilities:FetchAllValuesFromList function"))
            {
                SPListItemCollection matchedItemList = null;

                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                    {
                        SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];

                        SPQuery query        = new SPQuery();
                        query.ViewAttributes = "Scope=\"RecursiveAll\"";

                        if (!string.IsNullOrEmpty(field.View))
                        {
                            string viewQueryWhereString   = "";
                            string viewQueryOrderByString = "";

                            SPView view = LookupList.GetView(new Guid(field.View));

                            if (!String.IsNullOrEmpty(view.Query))
                            {
                                string viewQueryXML         = string.Format("<Query>{0}</Query>", view.Query);
                                XmlDocument viewQueryXMLDoc = new XmlDocument();
                                viewQueryXMLDoc.LoadXml(viewQueryXML);
                                XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                {
                                    viewQueryWhereString = whereNode.InnerXml;
                                }

                                XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                {
                                    viewQueryOrderByString = orderByNode.InnerXml;
                                }

                                viewQueryOrderByString = string.Format("<OrderBy>{0}</OrderBy>", viewQueryOrderByString);
                            }

                            if (!String.IsNullOrEmpty(viewQueryWhereString))
                            {
                                query.Query = "<Where>" + viewQueryWhereString + "</Where>" + viewQueryOrderByString;
                            }
                            else
                            {
                                query.Query = viewQueryOrderByString;
                            }

                            Utils.LogManager.write("Item fetch Query: " + query.Query);

                            matchedItemList = LookupList.GetItems(query);
                        }
                        else
                        {
                            matchedItemList = LookupList.Items;
                        }
                    }
                });

                Utils.LogManager.write("matchedItemList item Count: " + matchedItemList.Count);
                itemList = new List <ListItem>();
                foreach (SPListItem item in matchedItemList)
                {
                    //ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(field.LookupFieldName)].GetFieldValueAsText(item[new Guid(field.LookupFieldName)])), item.ID.ToString());
                    ListItem newItem = new ListItem(Convert.ToString(item.Fields.GetFieldByInternalName(field.LookupFieldName).GetFieldValueAsText(item[item.Fields.GetFieldByInternalName(field.LookupFieldName).Id])), item.ID.ToString());
                    if (!itemList.Contains(newItem))
                    {
                        itemList.Add(newItem);
                    }
                }

                Utils.LogManager.write("itemList item Count: " + itemList.Count);
            }
        }
示例#5
0
        public static void GetParametersValue(CCSCascadedLookupField field, out string WebUrl, out string LookupListName, out string FieldParentLinkedFieldName, out string FieldLookupFieldName, out string FieldViewWhereString, out string FieldViewOrderString)
        {
            using (new EnterExitLogger("Utilities:GetParametersValue function"))
            {
                WebUrl = ""; 
                LookupListName= "";
                FieldParentLinkedFieldName= "";
                FieldLookupFieldName= "";
                FieldViewWhereString= "";
                FieldViewOrderString = "";

                string webUrl = "";
                string lookupListName = "";
                string LookupFieldName = "";
                string ParentLinkedFieldName = "";
                string ViewWhereString = "";
                string ViewOrderString = "";
                Utils.LogManager.write("Field : " + field.Title);
                SPSecurity.RunWithElevatedPrivileges(delegate
                    {
                        using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                        {
                            SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];
                            webUrl = LookupWeb.Url;
                            Utils.LogManager.write("webUrl : " + webUrl);

                            lookupListName = LookupList.Title;
                            Utils.LogManager.write("lookupListName : " + lookupListName);

                            LookupFieldName = field.LookupFieldName;
                            Utils.LogManager.write("LookupFieldName : " + LookupFieldName);


                            if (!string.IsNullOrEmpty(field.GetParentLinkedColumnId()))
                            {
                                //string linked_column = field.GetProperty(CustomDropDownList.LINK_COLUMN);
                                SPField ParentLinkedField = LookupList.Fields[new Guid(field.GetParentLinkedColumnId())];
                                if (ParentLinkedField != null)
                                {
                                    ParentLinkedFieldName = ParentLinkedField.InternalName;
                                    Utils.LogManager.write("ParentLinkedFieldName : " + ParentLinkedFieldName);
                                }
                            }

                            if (!string.IsNullOrEmpty(field.View))
                            {
                                SPView view = LookupList.GetView(new Guid(field.View));

                                if (!String.IsNullOrEmpty(view.Query))
                                {
                                    string viewQueryXML = string.Format("<Query>{0}</Query>", view.Query);
                                    XmlDocument viewQueryXMLDoc = new XmlDocument();
                                    viewQueryXMLDoc.LoadXml(viewQueryXML);
                                    XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                    if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                    {
                                        ViewWhereString = whereNode.InnerXml;
                                        Utils.LogManager.write("ViewWhereString : " + ViewWhereString);
                                    }

                                    XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                    if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                    {
                                        ViewOrderString = orderByNode.InnerXml;
                                    }

                                    ViewOrderString = string.Format("<OrderBy>{0}</OrderBy>", ViewOrderString);
                                    Utils.LogManager.write("ViewOrderString : " + ViewOrderString);
                                }
                            }
                        }
                    });

                WebUrl = webUrl;
                LookupListName = lookupListName;
                FieldParentLinkedFieldName = ParentLinkedFieldName;
                FieldLookupFieldName = LookupFieldName;
                FieldViewWhereString = ViewWhereString;
                FieldViewOrderString = ViewOrderString;
            }
        }
示例#6
0
        public static void FetchAllValuesFromList(CCSCascadedLookupField field, ref List<ListItem> itemList)
        {
            using (new EnterExitLogger("Utilities:FetchAllValuesFromList function"))
            {
                SPListItemCollection matchedItemList = null;

                SPSecurity.RunWithElevatedPrivileges(delegate
                    {
                        using (SPWeb LookupWeb = SPContext.Current.Site.OpenWeb(((SPFieldLookup)field).LookupWebId))
                        {
                            SPList LookupList = LookupWeb.Lists[new Guid(field.LookupFieldListName)];

                            SPQuery query = new SPQuery();
                            query.ViewAttributes = "Scope=\"RecursiveAll\"";

                            if (!string.IsNullOrEmpty(field.View))
                            {
                                string viewQueryWhereString = "";
                                string viewQueryOrderByString = "";

                                SPView view = LookupList.GetView(new Guid(field.View));

                                if (!String.IsNullOrEmpty(view.Query))
                                {
                                    string viewQueryXML = string.Format("<Query>{0}</Query>", view.Query);
                                    XmlDocument viewQueryXMLDoc = new XmlDocument();
                                    viewQueryXMLDoc.LoadXml(viewQueryXML);
                                    XmlNode whereNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("Where");
                                    if (whereNode != null && !string.IsNullOrEmpty(whereNode.InnerXml))
                                    {
                                        viewQueryWhereString = whereNode.InnerXml;
                                    }

                                    XmlNode orderByNode = viewQueryXMLDoc.DocumentElement.SelectSingleNode("OrderBy");
                                    if (orderByNode != null && !string.IsNullOrEmpty(orderByNode.InnerXml))
                                    {
                                        viewQueryOrderByString = orderByNode.InnerXml;
                                    }

                                    viewQueryOrderByString = string.Format("<OrderBy>{0}</OrderBy>", viewQueryOrderByString);
                                }

                                if (!String.IsNullOrEmpty(viewQueryWhereString))
                                {
                                    query.Query = "<Where>" + viewQueryWhereString + "</Where>" + viewQueryOrderByString;
                                }
                                else
                                {
                                    query.Query = viewQueryOrderByString;
                                }

                                Utils.LogManager.write("Item fetch Query: " + query.Query);

                                matchedItemList = LookupList.GetItems(query);
                            }
                            else
                            {
                                matchedItemList = LookupList.Items;
                            }

                        }
                    });

                Utils.LogManager.write("matchedItemList item Count: " + matchedItemList.Count);
                itemList = new List<ListItem>();
                foreach (SPListItem item in matchedItemList)
                {
                    //ListItem newItem = new ListItem(Convert.ToString(item.Fields[new Guid(field.LookupFieldName)].GetFieldValueAsText(item[new Guid(field.LookupFieldName)])), item.ID.ToString());
                    ListItem newItem = new ListItem(Convert.ToString(item.Fields.GetFieldByInternalName(field.LookupFieldName).GetFieldValueAsText(item[item.Fields.GetFieldByInternalName(field.LookupFieldName).Id])), item.ID.ToString());
                    if (!itemList.Contains(newItem))
                    {
                        itemList.Add(newItem);
                    }
                }

                Utils.LogManager.write("itemList item Count: " + itemList.Count);
            }
        }
        public void OnSaveChange(SPField field, bool isNewField)
        {
            using (new EnterExitLogger("CCSCascadedLookupFieldEditor:OnSaveChange function"))
            {
                try
                {

                    CCSCascadedLookupField ccscascadeField = field as CCSCascadedLookupField;
                    if (ccscascadeField != null)
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate
                            {
                                using (SPWeb selWeb = SPContext.Current.Site.OpenWeb(new Guid(ddlWeb.SelectedItem.Value)))
                                {
                                    ccscascadeField.LookupWebId = selWeb.ID;
                                    Utils.LogManager.write("ccscascadeField.LookupWebId: " + selWeb.ID.ToString());
                                }
                            });

                        ccscascadeField.LookupList = (ddlList.SelectedItem != null ? ddlList.SelectedItem.Value : "");
                        Utils.LogManager.write("ccscascadeField.LookupList: " + ddlList.SelectedItem.Value);

                        ccscascadeField.LookupField = (ddlColumn.SelectedItem != null ? ddlColumn.SelectedItem.Value : "");
                        Utils.LogManager.write("ccscascadeField.LookupField: " + ddlColumn.SelectedItem.Value);

                        ccscascadeField.SourceWebID = ddlWeb.SelectedItem.Value;
                        Utils.LogManager.write("ccscascadeField.SourceWebID: " + ddlWeb.SelectedItem.Value);

                        ccscascadeField.LookupFieldListName = (ddlList.SelectedItem != null ? ddlList.SelectedItem.Value : "");
                        Utils.LogManager.write("ccscascadeField.LookupFieldListName: " + (ddlList.SelectedItem != null ? ddlList.SelectedItem.Value : ""));
                        
                        ccscascadeField.LookupFieldName = (ddlColumn.SelectedItem != null ? ddlColumn.SelectedItem.Value : "");
                        Utils.LogManager.write("ccscascadeField.LookupFieldName: " + (ddlColumn.SelectedItem != null ? ddlColumn.SelectedItem.Value : ""));
                        
                        ccscascadeField.ParentLinkedColumnName = (ddlParentColumn.SelectedItem != null ? ddlParentColumn.SelectedItem.Value : "");
                        Utils.LogManager.write("ccscascadeField.ParentLinkedColumnName: " + (ddlParentColumn.SelectedItem != null ? ddlParentColumn.SelectedItem.Value : ""));

                        ccscascadeField.AllowMultipleValues = cbxAllowMultiple.Checked;
                        Utils.LogManager.write("ccscascadeField.AllowMultipleValues: " + cbxAllowMultiple.Checked.ToString());
                        
                        ccscascadeField.AdvancedSetting = cbxAdvanceSettings.Checked;
                        Utils.LogManager.write("ccscascadeField.AdvancedSetting: " + cbxAdvanceSettings.Checked.ToString());
                        
                        ccscascadeField.View = (ddlView.SelectedItem != null ? ddlView.SelectedItem.Value : "");
                        Utils.LogManager.write("ccscascadeField.View: " + (ddlView.SelectedItem != null ? ddlView.SelectedItem.Value : ""));
                        
                        ccscascadeField.LinkToParent = cbxLinkParent.Checked;
                        Utils.LogManager.write("ccscascadeField.LinkToParent: " + cbxLinkParent.Checked.ToString());
                        
                        ccscascadeField.ShowAllOnEmpty = cbxShowallParentEmpty.Checked;
                        Utils.LogManager.write("ccscascadeField.ShowAllOnEmpty: " + cbxShowallParentEmpty.Checked.ToString());
                        
                        ccscascadeField.AllowNewEntry = cbxAllowNewValues.Checked;
                        Utils.LogManager.write("ccscascadeField.AllowNewEntry: " + cbxAllowNewValues.Checked.ToString());
                        
                        ccscascadeField.UseNewForm = cbxUseNewForm.Checked;
                        Utils.LogManager.write("ccscascadeField.UseNewForm: " + cbxUseNewForm.Checked.ToString());

                        ccscascadeField.SortByView = cbxSortByView.Checked;
                        Utils.LogManager.write("ccscascadeField.SortByView: " + cbxSortByView.Checked.ToString());
                        
                        ccscascadeField.AllowAutocomplete = false;
                        Utils.LogManager.write("ccscascadeField.AllowAutocomplete: False");

                        if (cbxRelationshipBehavior.Enabled && cbxRelationshipBehavior.Checked)
                        {
                            if (rbRestrictDelete.Enabled && rbRestrictDelete.Checked)
                            {
                                ccscascadeField.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.Restrict;
                                Utils.LogManager.write("ccscascadeField.RelationshipDeleteBehavior: Restrict");
                            }
                            else if (rbCascadeDelete.Enabled && rbCascadeDelete.Checked)
                            {
                                ccscascadeField.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.Cascade;
                                Utils.LogManager.write("ccscascadeField.RelationshipDeleteBehavior: Cascade");
                            }
                            else
                            {
                                ccscascadeField.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.None;
                                Utils.LogManager.write("ccscascadeField.RelationshipDeleteBehavior: None");
                            }
                        }
                        else
                        {
                            ccscascadeField.RelationshipDeleteBehavior = SPRelationshipDeleteBehavior.None;
                            Utils.LogManager.write("ccscascadeField.RelationshipDeleteBehavior: None");
                        }

                        ccscascadeField.AdditionalFilters = GetAdditonalFilters();
                        Utils.LogManager.write("ccscascadeField.AdditionalFilters: " + ccscascadeField.AdditionalFilters);

                        if (isNewField)
                        {
                            ccscascadeField.AdditionalFields = GetAdditonalFields();
                            Utils.LogManager.write("ccscascadeField.AdditionalFields: " + ccscascadeField.AdditionalFields);
                        }
                        else
                        {
                            ccscascadeField.AdditionalFields = "";
                            if (cblAdditionalFields.Items != null && cblAdditionalFields.Items.Count > 0)
                            {
                                foreach (ListItem li in cblAdditionalFields.Items)
                                {
                                    if (li.Selected)
                                    {
                                        if (!ccscascadeField.ParentList.Fields.ContainsField(ccscascadeField.Title + " : " + li.Text))
                                        {
                                            //create a new field
                                            Utils.LogManager.write("Creating AddintionField Name: " + ccscascadeField.Title + " : " + li.Text);
                                            string depLookUp = ccscascadeField.ParentList.Fields.AddDependentLookup(ccscascadeField.Title + " : " + li.Text, ccscascadeField.Id);
                                            SPFieldLookup fieldDepLookup = (SPFieldLookup)ccscascadeField.ParentList.Fields.GetFieldByInternalName(depLookUp);

                                            if (fieldDepLookup != null)
                                            {
                                                fieldDepLookup.LookupWebId = ccscascadeField.LookupWebId;
                                                fieldDepLookup.LookupField = li.Value;
                                                fieldDepLookup.Update();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (ccscascadeField.ParentList.Fields.ContainsField(ccscascadeField.Title + " : " + li.Text))
                                        {
                                            //delete field if exist
                                            Utils.LogManager.write("Deleting AddintionField Name: " + ccscascadeField.Title + " : " + li.Text);
                                            ccscascadeField.ParentList.Fields.GetField(ccscascadeField.Title + " : " + li.Text).Delete();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utils.LogManager.write("Exception Occurs in OnSaveChanges Function. \r\nError Message: " + ex.Message + "\r\nStack Trace: " + ex.StackTrace, "error");
                }
            }
        }
 string GetControlId(CCSCascadedLookupField field)
 {
     using (new EnterExitLogger("CCSCascadedLookupControl:GetControlId function"))
     {
         if (field.AllowMultipleValues)
         {
             Utils.LogManager.write("Field: " + field.Title + ", ControlId: " + lbLeftBox.ClientID + ";#" + lbRightBox.ClientID); 
             return lbLeftBox.ClientID + ";#" + lbRightBox.ClientID;
         }
         else
         {
             Utils.LogManager.write("Field: " + field.Title + ", ControlId: " + ddlCCSCascadeFieldControl.ClientID);
             return ddlCCSCascadeFieldControl.ClientID;
         }
     }
 }
        void RegisterAddCascadedControlScript(CCSCascadedLookupField field, string parentControlId, string ParentControlType)
        {
            using (new EnterExitLogger("CCSCascadedLookupControl:RegisterAddCascadedControlScript function"))
            {
                string webUrl = "";
                string LookuplistName = "";
                string ParentLinkedFieldName = "";
                string LookupFieldName = "";
                string ViewWhereString = "";
                string ViewOrderString = "";

                string controlId = GetControlId(field);

                Utilities.GetParametersValue(field, out webUrl, out LookuplistName, out ParentLinkedFieldName, out LookupFieldName, out ViewWhereString, out ViewOrderString);

                Utils.LogManager.write("RegisterAddCascadedControlScript: new AddCascadedControl('" + controlId + "', " + field.AllowMultipleValues.ToString().ToLower() + ", " + field.ShowAllOnEmpty.ToString().ToLower() + ", '" + hFieldValue.ClientID + "','" + parentControlId + "', " + ParentControlType + ", '" + webUrl + "', '" + LookuplistName + "', '" + ParentLinkedFieldName + "', '" + LookupFieldName + "', '" + ViewWhereString + "', '" + ViewOrderString + "');");
                        
                //function AddCascadedControl(controlId, isAllowMultiple, allValuesOnEmpty, parentControlId, parentControlType, webUrl, lookupListName, linkedParentfield, lookupTargetField, viewWhereString, viewOrderString) {
                string AddCascadeControlScript = "new AddCascadedControl('" + controlId + "', " + field.AllowMultipleValues.ToString().ToLower() + ", " + field.ShowAllOnEmpty.ToString().ToLower() + ", '" + hFieldValue.ClientID + "','" + parentControlId + "', " + ParentControlType + ", '" + webUrl + "', '" + LookuplistName + "', '" + ParentLinkedFieldName + "', '" + LookupFieldName + "', '" + ViewWhereString + "', '" + ViewOrderString + "');";

                Utils.LogManager.write("Register the script");
                Page.ClientScript.RegisterStartupScript(new object().GetType(), "ChildControl" + this.Field.Id.ToString("n"), "if(true){ " + AddCascadeControlScript + "}", true);
            }

        }
        object GetParentFieldValuePostBack(CCSCascadedLookupField field)
        {
            using (new EnterExitLogger("CCSCascadedLookupControl:GetParentFieldValuePostBack function"))
            {
                if (field != null)
                {
                    if (field.LinkToParent)
                    {
                        string ParentColumnId = field.GetParentColumnId();
                        if (!string.IsNullOrEmpty(ParentColumnId))
                        {
                            SPFieldLookup fieldParent = SPContext.Current.List.Fields[new Guid(ParentColumnId)] as SPFieldLookup;

                            if (fieldParent != null)
                            {
                                List<Control> collect = new List<Control>();

                                Utilities.FindControlRecursive(Page, typeof(MultipleLookupField), ref collect);
                                if (collect.Count > 0)
                                {
                                    foreach (Control ctrl in collect)
                                    {
                                        if (((MultipleLookupField)ctrl).FieldName.Equals(fieldParent.InternalName, StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            Utils.LogManager.write("Return Parent Field : " + fieldParent.Title + ", MultipleLookupField Value: " + (((MultipleLookupField)ctrl).Value != null ? ((MultipleLookupField)ctrl).Value : "NULL"));
                                            return ((MultipleLookupField)ctrl).Value;
                                        }
                                    }
                                }

                                collect.Clear();
                                Utilities.FindControlRecursive(Page, typeof(CCSCascadedLookupControl), ref collect);
                                if (collect.Count > 0)
                                {
                                    foreach (Control ctrl in collect)
                                    {
                                        if (((CCSCascadedLookupControl)ctrl).FieldName.Equals(fieldParent.InternalName, StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            Utils.LogManager.write("Return Parent Field : " + fieldParent.Title + ", CCSCascadedLookupControl Value: " + (((CCSCascadedLookupControl)ctrl).Value != null ? ((CCSCascadedLookupControl)ctrl).Value : "NULL"));
                                            return ((CCSCascadedLookupControl)ctrl).Value;
                                        }
                                    }
                                }

                                collect.Clear();
                                Utilities.FindControlRecursive(Page, typeof(LookupField), ref collect);

                                if (collect.Count > 0)
                                {
                                    foreach (Control ctrl in collect)
                                    {
                                        if (((LookupField)ctrl).FieldName.Equals(fieldParent.InternalName, StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            Utils.LogManager.write("Return Parent Field : " + fieldParent.Title + ", LookupField Value: " + (((LookupField)ctrl).Value != null ? ((LookupField)ctrl).Value : "NULL"));
                                            return ((LookupField)ctrl).Value;
                                        }
                                    }
                                }

                            }
                        }
                    }
                }

                Utils.LogManager.write("Return Value: Null");
                return null;
            }
        }
        object GetParentFieldValueStart(CCSCascadedLookupField field)
        {
            using (new EnterExitLogger("CCSCascadedLookupControl:GetParentFieldValueStart function"))
            {
                if (field.LinkToParent)
                {
                    string ParentColumnId = field.GetParentColumnId();
                    if (!string.IsNullOrEmpty(ParentColumnId))
                    {
                        SPFieldLookup fieldParent = SPContext.Current.List.Fields[new Guid(ParentColumnId)] as SPFieldLookup;
                        if (fieldParent.AllowMultipleValues)
                        {
                            Utils.LogManager.write("Parent Field : " + fieldParent.Title + ", Allow Multiple Values: true");
                            SPFieldLookupValueCollection valColl = fieldParent.FieldRenderingControl.ItemFieldValue as SPFieldLookupValueCollection;
                            if (valColl != null && valColl.Count > 0)
                            {
                                Utils.LogManager.write("Return Parent Field : " + fieldParent.Title + ", Value: " + valColl.ToString());
                                return valColl;
                            }

                            string val = fieldParent.FieldRenderingControl.ItemFieldValue as string;

                            if (!string.IsNullOrEmpty(val))
                            {
                                string[] vals = val.Split(new string[] { ";#" }, StringSplitOptions.None);

                                if (vals.Length >= 2)
                                {
                                    valColl = new SPFieldLookupValueCollection();
                                    for (int i = 0; i <= vals.Length - 2; i = i + 2)
                                    {
                                        valColl.Add(new SPFieldLookupValue(int.Parse(vals[i]), vals[i + 1]));
                                    }

                                    Utils.LogManager.write("Return Parent Field : " + fieldParent.Title + ", Value: " + valColl.ToString());
                                    return valColl;
                                }
                            }
                        }
                        else
                        {
                            Utils.LogManager.write("Parent Field : " + fieldParent.Title + ", Allow Multiple Values: false");
                            
                            if (fieldParent.FieldRenderingControl.ItemFieldValue != null)
                            {
                                SPFieldLookupValue lookupVal = fieldParent.FieldRenderingControl.ItemFieldValue as SPFieldLookupValue;

                                if (lookupVal != null)
                                {
                                    Utils.LogManager.write("Return Parent Field : " + fieldParent.Title + ", Value: " + lookupVal.ToString());
                                    return lookupVal;
                                }
                                else
                                {
                                    string val = fieldParent.FieldRenderingControl.ItemFieldValue.ToString();
                                    if (!string.IsNullOrEmpty(val))
                                    {
                                        string[] vals = val.Split(new string[] { ";#" }, StringSplitOptions.None);
                                        if (vals.Length == 2)
                                        {
                                            Utils.LogManager.write("Return Parent Field : " + fieldParent.Title + ", Value: " + vals[0]);
                                            return new SPFieldLookupValue(int.Parse(vals[0]), vals[1]);
                                        }
                                        else if (vals.Length == 1)
                                        {
                                            Utils.LogManager.write("Return Parent Field : " + fieldParent.Title + ", Value: " + vals[0]);
                                            return vals[0];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                Utils.LogManager.write("Return Value: Null");
                return null;
            }
        }
 object GetParentFieldValue(CCSCascadedLookupField field)
 {
     using (new EnterExitLogger("CCSCascadedLookupControl:GetParentFieldValue function"))
     {
         if (this.Page.IsPostBack)
         {
             return GetParentFieldValuePostBack(field);
         }
         else
         {
             return GetParentFieldValueStart(field);
         }
     }
 }
        private void ShowControls(CCSCascadedLookupField field)
        {
            using (new EnterExitLogger("CCSCascadedLookupControl:ShowControls function"))
            {
                SingleValuePanel = (Panel)TemplateContainer.FindControl("SingleValuePanel");
                MultipleValuePanel = (Panel)TemplateContainer.FindControl("MultipleValuePanel");
                NewEntryPanel = (Panel)TemplateContainer.FindControl("NewEntryPanel");

                ddlCCSCascadeFieldControl = (HtmlSelect)TemplateContainer.FindControl("ddlCCSCascadeFieldControl");
                lbLeftBox = (HtmlSelect)TemplateContainer.FindControl("lbLeftBox");
                lbRightBox = (HtmlSelect)TemplateContainer.FindControl("lbRightBox");
                btnAdd = (Button)TemplateContainer.FindControl("btnAdd");
                btnRemove = (Button)TemplateContainer.FindControl("btnRemove");

                lnkNewEntry = (LinkButton)TemplateContainer.FindControl("lnkNewEntry");
                txtNewEntry = (TextBox)TemplateContainer.FindControl("txtNewEntry");
                lnkAdd = (LinkButton)TemplateContainer.FindControl("lnkAdd");
                lnkCancel = (LinkButton)TemplateContainer.FindControl("lnkCancel");

                hFieldValue = (HtmlInputHidden)TemplateContainer.FindControl("hFieldValue");

                lbLeftBox.EnableViewState = true;
                lbRightBox.EnableViewState = true;
                ddlCCSCascadeFieldControl.EnableViewState = true;

                ErrorText = (Literal)TemplateContainer.FindControl("ErrorText");

                Utils.LogManager.write("Initilized All Controls");
                ErrorText.Visible = false;

                if (field.AllowMultipleValues)
                {
                    Utils.LogManager.write("Field: " + field.Title + ", Allow Multiple Values: true");
                    SingleValuePanel.Visible = false;
                    MultipleValuePanel.Visible = true;

                    lbLeftBox.Multiple = true;
                    lbRightBox.Multiple = true;

                    Utils.LogManager.write("Adding Events on controls");
                    
                    lbLeftBox.Attributes.Add("ondblclick", "Listbox_MoveAcross('" + lbLeftBox.ClientID + "','" + lbRightBox.ClientID + "'); SetValueFromListBox('" + hFieldValue.ClientID + "','" + lbRightBox.ClientID + "'); UpdateMyChildControls('" + lbLeftBox.ClientID + ";#" + lbRightBox.ClientID + "');");
                    lbRightBox.Attributes.Add("ondblclick", "Listbox_MoveAcross('" + lbRightBox.ClientID + "','" + lbLeftBox.ClientID + "'); SetValueFromListBox('" + hFieldValue.ClientID + "','" + lbRightBox.ClientID + "'); UpdateMyChildControls('" + lbLeftBox.ClientID + ";#" + lbRightBox.ClientID + "');");

                    btnAdd.Attributes.Add("onclick", "Listbox_MoveAcross('" + lbLeftBox.ClientID + "','" + lbRightBox.ClientID + "'); SetValueFromListBox('" + hFieldValue.ClientID + "','" + lbRightBox.ClientID + "'); UpdateMyChildControls('" + lbLeftBox.ClientID + ";#" + lbRightBox.ClientID + "'); return false;");
                    btnRemove.Attributes.Add("onclick", "Listbox_MoveAcross('" + lbRightBox.ClientID + "','" + lbLeftBox.ClientID + "'); SetValueFromListBox('" + hFieldValue.ClientID + "','" + lbRightBox.ClientID + "'); UpdateMyChildControls('" + lbLeftBox.ClientID + ";#" + lbRightBox.ClientID + "'); return false;");

                }
                else
                {
                    Utils.LogManager.write("Field: " + field.Title + ", Allow Multiple Values: false");
                    SingleValuePanel.Visible = true;
                    MultipleValuePanel.Visible = false;

                    Utils.LogManager.write("Adding Event on control");
                    ddlCCSCascadeFieldControl.Attributes.Add("onchange", "SetValueFromDropDown('" + hFieldValue.ClientID + "','" + ddlCCSCascadeFieldControl.ClientID + "'); UpdateMyChildControls('" + ddlCCSCascadeFieldControl.ClientID + "');");
                }

                if (field.AllowNewEntry)
                {
                    Utils.LogManager.write("Field: " + field.Title + ", Allow New Entry: true");
                    NewEntryPanel.Visible = true;

                    lnkNewEntry.Visible = true;
                    txtNewEntry.Visible = true;
                    lnkAdd.Visible = true;
                    lnkCancel.Visible = true;

                    txtNewEntry.Style.Add(HtmlTextWriterStyle.Display, "none");
                    lnkAdd.Style.Add(HtmlTextWriterStyle.Display, "none");
                    lnkCancel.Style.Add(HtmlTextWriterStyle.Display, "none");

                    if (field.UseNewForm)
                    {
                        Utils.LogManager.write("Field: " + field.Title + ", Use New Form: true");
                        SPSecurity.RunWithElevatedPrivileges(delegate
                            {
                                using (SPWeb spWeb = SPContext.Current.Site.OpenWeb(field.LookupWebId))
                                {
                                    string weburl = spWeb.Url;
                                    SPList sourceList = spWeb.Lists[new Guid(field.LookupFieldListName)];
                                    SPForm form = sourceList.Forms[PAGETYPE.PAGE_NEWFORM];
                                    string url = form.Url;
                                    url = weburl + "/" + form.Url;
                                    string title = field.InternalName;

                                    lnkNewEntry.OnClientClick = "javascript:SP.UI.ModalDialog.showModalDialog({ url: '" + url + "', title: '" + title + "', dialogReturnValueCallback:  callbackMethod" + this.Field.Id.ToString("n") + "});";
                                }
                            });
                    }
                    else
                    {
                        Utils.LogManager.write("Field: " + field.Title + ", Use New Form: false");
                        lnkNewEntry.OnClientClick = "document.getElementById('" + txtNewEntry.ClientID + "').value = ''; document.getElementById('" + txtNewEntry.ClientID + "').style.display=''; document.getElementById('" + lnkAdd.ClientID + "').style.display=''; document.getElementById('" + lnkCancel.ClientID + "').style.display=''; return false;";

                        lnkAdd.OnClientClick = "createListItem('" + GetControlId(field) + "','" + txtNewEntry.ClientID + "'); document.getElementById('" + txtNewEntry.ClientID + "').value = ''; document.getElementById('" + txtNewEntry.ClientID + "').style.display='none'; document.getElementById('" + lnkAdd.ClientID + "').style.display='none'; document.getElementById('" + lnkCancel.ClientID + "').style.display='none'; return false;";
                        lnkCancel.OnClientClick = "document.getElementById('" + txtNewEntry.ClientID + "').value = ''; document.getElementById('" + txtNewEntry.ClientID + "').style.display='none'; document.getElementById('" + lnkAdd.ClientID + "').style.display='none'; document.getElementById('" + lnkCancel.ClientID + "').style.display='none'; return false;";
                    }
                }
                else
                {
                    Utils.LogManager.write("Field: " + field.Title + ", Allow New Entry: false");
                    NewEntryPanel.Visible = false;
                }
            }
        }