Beispiel #1
0
        private string[] GetValuesArray(ControlCollection coll)
        {
            List <string> values = new List <string>();

            foreach (Control control in coll)
            {
                if (control is RadioButtonList)
                {
                    for (int i = 0; i < ((RadioButtonList)control).Items.Count; i++)
                    {
                        values.Add(string.Format("{0}_{1}:{2}", control.ClientID, i, ((RadioButtonList)control).Items[i].Selected.ToString().ToLower()));
                    }
                }
                else if (control is CheckBox && control.Parent is CheckBoxList)
                {
                    // checked checkboxes within a list appear as real controls
                }
                else if (control is CheckBoxList)
                {
                    for (int i = 0; i < ((CheckBoxList)control).Items.Count; i++)
                    {
                        values.Add(string.Format("{0}_{1}:{2}", control.ClientID, i, ((CheckBoxList)control).Items[i].Selected.ToString().ToLower()));
                    }
                }
                else if (control is ListControl)
                {
                    StringBuilder data      = new StringBuilder();
                    StringBuilder selection = new StringBuilder();
                    foreach (ListItem item in ((ListControl)control).Items)
                    {
                        data.AppendLine(item.Text);
                        selection.AppendLine(item.Selected.ToString().ToLower());
                    }
                    values.Add(string.Format("{0}:data:{1}", control.ClientID, Uri.EscapeDataString(data.ToString())));
                    values.Add(string.Format("{0}:selection:{1}", control.ClientID, Uri.EscapeDataString(selection.ToString())));
                }
                else if (control is IEditableTextControl)
                {
                    values.Add(string.Format("{0}:{1}", control.ClientID, Uri.EscapeDataString(((IEditableTextControl)control).Text)));
                }
                else if (control is ICheckBoxControl)
                {
                    values.Add(string.Format("{0}:{1}", control.ClientID, ((ICheckBoxControl)control).Checked.ToString().ToLower()));
                }
                else if (control is AjaxControlToolkit.HTMLEditor.Editor)
                {
                    AjaxControlToolkit.HTMLEditor.Editor editorControl = control as AjaxControlToolkit.HTMLEditor.Editor;
                    values.Add(string.Format("{0}:{1}", editorControl.ClientID, editorControl.Content));
                }

                values.AddRange(GetValuesArray(control.Controls));
            }
            return(values.ToArray());
        }
Beispiel #2
0
        protected override void OnInit(EventArgs e)
        {
            Controls.Add(new LiteralControl("\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.or" +
                                            "g/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xh" +
                                            "tml\" style=\"overflow: hidden\">\n"));
            HtmlHead head = new HtmlHead();

            Controls.Add(head);
            head.Controls.Add(new LiteralControl(@"
    <script type=""text/javascript"">
        function pageLoad() {
            var m = location.href.match(/(\?|&)id=(.+?)(&|$)/);
            if (!(parent && parent.window.Web) || !m) return;
            var elem = parent.window.$get(m[2]);
            if (!elem) return;
            if (typeof (FieldEditor_SetValue) !== ""undefined"")
                FieldEditor_SetValue(elem.value);
            else
                alert('The field editor does not implement ""FieldEditor_SetValue"" function.');
            if (typeof (FieldEditor_GetValue) !== ""undefined"")
                parent.window.Web.DataView.Editors[elem.id] = { 'GetValue': FieldEditor_GetValue, 'SetValue': FieldEditor_SetValue };
            else
                alert('The field editor does not implement ""FieldEditor_GetValue"" function.');
        }
    </script>
"));
            head.Controls.Add(new LiteralControl("\n    <style type=\"text/css\">\n        .ajax__htmleditor_editor_container\n        {" +
                                                 "\n            border-width:0px!important;\n        }\n\n        .ajax__htmleditor_ed" +
                                                 "itor_bottomtoolbar\n        {\n            padding-top:2px!important;\n        }\n  " +
                                                 "  </style>"));
            Controls.Add(new LiteralControl("\n<body style=\"margin: 0px; padding: 0px; background-color: #fff;\">\n"));
            HtmlForm form = new HtmlForm();

            Controls.Add(form);
            ToolkitScriptManager sm = new ToolkitScriptManager();

            sm.ScriptMode = ScriptMode.Release;
            sm.EnableCdn  = false;
            form.Controls.Add(sm);
            string  controlName = Request.Params["control"];
            Control c           = null;

            if (!(String.IsNullOrEmpty(controlName)))
            {
                try
                {
                    c = LoadControl(String.Format("~/Controls/{0}.ascx", controlName));
                }
                catch (Exception)
                {
                }
                if (c != null)
                {
                    object[] editorAttributes = c.GetType().GetCustomAttributes(typeof(AquariumFieldEditorAttribute), true);
                    if (editorAttributes.Length == 0)
                    {
                        c = null;
                    }
                }
                else
                if (controlName == "RichEditor")
                {
                    AjaxControlToolkit.HTMLEditor.Editor editor = new AjaxControlToolkit.HTMLEditor.Editor();
                    editor.AutoFocus      = false;
                    editor.InitialCleanUp = true;
                    editor.NoScript       = true;
                    editor.Width          = new Unit("100%");
                    editor.Height         = new Unit(250);
                    c = editor;
                }
            }
            if (c == null)
            {
                throw new HttpException(404, String.Empty);
            }
            else
            {
                form.Controls.Add(c);
                if (!((c.GetType() == typeof(System.Web.UI.UserControl))))
                {
                    this.ClientScript.RegisterClientScriptBlock(GetType(), "ClientScripts", String.Format("function FieldEditor_GetValue(){{return $find(\'{0}\').get_content();}}\nfunction Fi" +
                                                                                                          "eldEditor_SetValue(value) {{$find(\'{0}\').set_content(value);}}", c.ClientID), true);
                }
            }
            Controls.Add(new LiteralControl("\n\n</body>\n</html>"));
            base.OnInit(e);
            EnableViewState = false;
        }