private void ProcessAjaxPostBack()
    {
        if (RequestHelper.IsPostBack())
        {
            string eventArgument = Request.Params.Get("__EVENTARGUMENT");

            if (!string.IsNullOrEmpty(eventArgument))
            {
                string   errorMessage;
                string[] data = eventArgument.Split(':');

                switch (data[0])
                {
                case "loadSettings":
                {
                    FieldName = data[1];
                    LoadSettings(FieldName);
                }
                break;

                case "remove":
                {
                    // Hide selected field from form
                    FieldName    = string.Empty;
                    errorMessage = HideField(data[2]);
                    if (!String.IsNullOrEmpty(errorMessage))
                    {
                        ShowError(errorMessage);
                        return;
                    }

                    mReloadForm = true;
                    pnlSettings.Update();
                }
                break;

                case "hideSettingsPanel":
                {
                    FieldName = string.Empty;
                    pnlSettings.Update();
                }
                break;

                case "saveSettings":
                {
                    FormFieldInfo ffi = FormInfo.GetFormField(FieldName);
                    if (ffi != null)
                    {
                        FormFieldInfo originalFieldInfo = (FormFieldInfo)ffi.Clone();
                        pnlSettings.SaveSettings(ffi);

                        errorMessage = SaveFormDefinition(originalFieldInfo, ffi);
                        if (!String.IsNullOrEmpty(errorMessage))
                        {
                            ShowError(errorMessage);
                            return;
                        }

                        mReloadField = true;
                    }
                }
                break;

                case "addField":
                {
                    FormFieldInfo ffi = PrepareNewField(data[1]);
                    FieldName = ffi.Name;

                    errorMessage = AddField(ffi, data[2], ValidationHelper.GetInteger(data[3], -1));
                    if (!String.IsNullOrEmpty(errorMessage))
                    {
                        ShowError(errorMessage);
                        return;
                    }

                    LoadSettings(FieldName);
                    mReloadForm = true;
                }
                break;

                case "clone":
                {
                    FormFieldInfo ffi = FormInfo.GetFormField(data[2]);
                    if (ffi != null)
                    {
                        string newFieldName;
                        errorMessage = CloneField(ffi, out newFieldName);
                        if (!String.IsNullOrEmpty(errorMessage))
                        {
                            ShowError(errorMessage);
                            return;
                        }

                        FieldName = newFieldName;

                        LoadSettings(FieldName);
                        mReloadForm = true;
                    }
                }
                break;
                }
            }
        }
    }
    /// <summary>
    /// Returns FormFieldInfo structure with form data.
    /// </summary>   
    /// <param name="ffiOriginal">Original field info</param>
    private FormFieldInfo FillFormFieldInfoStructure(FormFieldInfo ffiOriginal)
    {
        string selectedType = string.Empty;
        DataRow settingsData = null;
        FormFieldInfo formFieldInfo;

        if (ffiOriginal != null)
        {
            // Field info with original information
            formFieldInfo = (FormFieldInfo)ffiOriginal.Clone();

            if (chkDisplayInForm.Checked)
            {
                // Reset control settings (hidden field's settings are preserved)
                formFieldInfo.Settings.Clear();
                formFieldInfo.SettingsMacroTable.Clear();
            }
        }
        else
        {
            formFieldInfo = new FormFieldInfo();
        }

        formFieldInfo.IsDummyField = IsDummyField;
        formFieldInfo.IsDummyFieldFromMainForm = IsDummyFieldFromMainForm;
        formFieldInfo.IsExtraField = IsExtraField;

        // Load FormFieldInfo with data from database configuration section
        databaseConfiguration.FieldInfo = formFieldInfo;
        databaseConfiguration.Save();

        // Do not save aditional field settings if field is hidden
        if (chkDisplayInForm.Checked)
        {
            // Field appearance section
            fieldAppearance.FieldInfo = formFieldInfo;
            fieldAppearance.Save();
            selectedType = fieldAppearance.FieldType;

            // Validation section
            validationSettings.FieldInfo = formFieldInfo;
            validationSettings.Save();

            // Design section
            cssSettings.FieldInfo = formFieldInfo;
            cssSettings.Save();

            // HtmlEnvelope section
            htmlEnvelope.FieldInfo = formFieldInfo;
            htmlEnvelope.Save();

            // Field advanced section
            formFieldInfo.SetPropertyValue(FormFieldPropertyEnum.VisibleMacro, fieldAdvancedSettings.VisibleMacro, true);
            formFieldInfo.SetPropertyValue(FormFieldPropertyEnum.EnabledMacro, fieldAdvancedSettings.EnabledMacro, true);
            formFieldInfo.DisplayInSimpleMode = fieldAdvancedSettings.DisplayInSimpleMode;
            formFieldInfo.HasDependingFields = fieldAdvancedSettings.HasDependingFields;
            formFieldInfo.DependsOnAnotherField = fieldAdvancedSettings.DependsOnAnotherField;

            // Get control settings data
            settingsData = controlSettings.FormData;

            // Store macro table
            formFieldInfo.SettingsMacroTable = controlSettings.MacroTable;
        }

        // Determine if it is external column
        formFieldInfo.External |= IsSystemFieldSelected;

        if (((Mode == FieldEditorModeEnum.BizFormDefinition) || (Mode == FieldEditorModeEnum.SystemTable) ||
            (Mode == FieldEditorModeEnum.AlternativeBizFormDefinition) || (Mode == FieldEditorModeEnum.AlternativeSystemTable))
            && (databaseConfiguration.AttributeType == FieldDataType.File))
        {
            // Allow to save <guid>.<extension>
            formFieldInfo.DataType = FieldDataType.Text;
            formFieldInfo.Size = 500;
        }
        else if (databaseConfiguration.AttributeType == FieldDataType.DocAttachments)
        {
            formFieldInfo.DataType = FieldDataType.DocAttachments;
            formFieldInfo.Size = 200;
        }
        else
        {
            formFieldInfo.DataType = databaseConfiguration.AttributeType;
            formFieldInfo.Size = ValidationHelper.GetInteger(databaseConfiguration.AttributeSize, 0);
            formFieldInfo.Precision = ValidationHelper.GetInteger(databaseConfiguration.AttributePrecision, -1);
        }

        formFieldInfo.Visible = chkDisplayInForm.Checked;

        formFieldInfo.DisplayIn = String.Empty;
        if (chkDisplayInDashBoard.Checked)
        {
            formFieldInfo.DisplayIn = DisplayIn;
        }

        // Store field type
        if (formFieldInfo.Visible)
        {
            formFieldInfo.Settings["controlname"] = selectedType;
        }

        // Store settings
        if ((settingsData != null) && (settingsData.ItemArray.Length > 0))
        {
            foreach (DataColumn column in settingsData.Table.Columns)
            {
                formFieldInfo.Settings[column.ColumnName] = settingsData.Table.Rows[0][column.Caption];
            }
        }

        formFieldInfo.FieldType = FormFieldControlTypeEnum.CustomUserControl;

        return formFieldInfo;
    }
    /// <summary>
    /// Returns FormFieldInfo structure with form data.
    /// </summary>   
    /// <param name="ffiOriginal">Original field info</param>
    private FormFieldInfo FillFormFieldInfoStructure(FormFieldInfo ffiOriginal)
    {
        FormFieldInfo formFieldInfo;

        if (ffiOriginal != null)
        {
            // Field info with original information
            formFieldInfo = (FormFieldInfo)ffiOriginal.Clone();

            if (chkDisplayInForm.Checked)
            {
                // Reset control settings (hidden field's settings are preserved)
                formFieldInfo.Settings.Clear();
                formFieldInfo.SettingsMacroTable.Clear();
            }
        }
        else
        {
            formFieldInfo = new FormFieldInfo();
        }

        // Set data type first to ensure proper further processing
        SetFieldDataType(formFieldInfo);

        formFieldInfo.IsDummyField = IsDummyField;
        formFieldInfo.IsDummyFieldFromMainForm = IsDummyFieldFromMainForm;
        formFieldInfo.IsExtraField = IsExtraField;

        // Load FormFieldInfo with data from database configuration section
        databaseConfiguration.FieldInfo = formFieldInfo;
        databaseConfiguration.Save();

        SetFieldAppearance(formFieldInfo);

        // Determine if it is external column
        formFieldInfo.External |= IsSystemFieldSelected;

        return formFieldInfo;
    }