Example #1
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public override object Clone()
        {
            ToolbarDropDownList copy = (ToolbarDropDownList)base.Clone();

            copy.SelectedIndexChanged = this.SelectedIndexChanged;

            copy._List = new InternalDropDownList();
            if (this._IsTrackingVS)
            {
                ((IStateManager)copy).TrackViewState();
            }

            foreach (ListItem item in this._List.Items)
            {
                ListItem newItem = new ListItem(item.Text, item.Value);
                if (item.Selected)
                {
                    newItem.Selected = true;
                }

                copy._List.Items.Add(newItem);
            }

            foreach (string key in this._List.Attributes.Keys)
            {
                copy._List.Attributes.Add(key, this._List.Attributes[key]);
            }

            foreach (string key in this._List.VS.Keys)
            {
                PropertyInfo pinfo = copy._List.GetType().GetProperty(key);
                if ((pinfo != null) && pinfo.CanRead && pinfo.CanWrite)
                {
                    // Try to be more gentle
                    object obj = pinfo.GetValue(this._List, null);
                    pinfo.SetValue(copy._List, obj, null);
                }
                else
                {
                    // Brute force copy the ViewState
                    object obj = this._List.VS[key];
                    if (obj is ICloneable)
                    {
                        obj = ((ICloneable)obj).Clone();
                    }
                    copy._List.VS[key] = obj;
                }
            }

            copy._List.Font.CopyFrom(this._List.Font);

            return(copy);
        }
Example #2
0
        /// <summary>
        /// Renders the control for an uplevel browser.
        /// </summary>
        /// <param name="writer">The HtmlTextWriter object that receives the control content.</param>
        protected override void RenderUpLevelPath(HtmlTextWriter writer)
        {
            writer.Write("<?XML:NAMESPACE PREFIX=\"" + TagNamespace
                         + "\" /><?IMPORT NAMESPACE=\"" + TagNamespace + "\" IMPLEMENTATION=\""
                         + AddPathToFilename("toolbar.htc") + "\" />");
            writer.WriteLine();

            AddAttributesToRender(writer);

            if (Orientation == Orientation.Vertical)
            {
                writer.AddAttribute("orientation", "vertical");
            }

            if (Page != null)
            {
                // We replace the '<replaceme>' with event.flatIndex so that we get the actual value
                // of the variable at runtime and not the string 'event.flatIndex'
                string postBack      = "{setAttribute('_submitting', 'true');try{" + Page.GetPostBackEventReference(this, "<replaceme>").Replace("'<replaceme>'", "event.flatIndex") + ";}catch(e){setAttribute('_submitting', 'false');}}";
                string checkNode     = "if (event.srcNode != null) ";
                string checkPostBack = "if ((event.srcNode.getType() != 'checkbutton') || (event.srcNode.getAttribute('_autopostback') != null)) if (getAttribute('_submitting') != 'true')";
                string setHelper     = HelperID + ".value+=((event.srcNode.getAttribute('selected')=='true')?'+':'-')+event.flatIndex+';';";

                writer.AddAttribute("oncheckchange", "JScript:" + checkNode + setHelper);
                writer.AddAttribute("onbuttonclick", "JScript:" + checkNode + checkPostBack + postBack);

                string readyScript = "JScript:try{" + HelperID + ".value = ''}catch(e){}";
                foreach (ToolbarItem item in Items)
                {
                    ToolbarDropDownList ddl  = item as ToolbarDropDownList;
                    ToolbarTextBox      tbox = item as ToolbarTextBox;
                    if (ddl != null)
                    {
                        ListItem selItem = ddl.SelectedItem;
                        readyScript += "try{" + ddl.HelperID + ".value = getItem(" + ddl.Index + ").getAttribute('value');}catch(e){}";
                    }
                    else if (tbox != null)
                    {
                        readyScript += "try{" + tbox.HelperID + ".value = getItem(" + tbox.Index + ").getAttribute('value');}catch(e){}";
                    }
                }
                writer.AddAttribute("onwcready", readyScript);
            }

            string style = DefaultStyle.CssText;

            if (style != String.Empty)
            {
                writer.AddAttribute("defaultstyle", style);
            }
            style = HoverStyle.CssText;
            if (style != String.Empty)
            {
                writer.AddAttribute("hoverstyle", style);
            }
            style = SelectedStyle.CssText;
            if (style != String.Empty)
            {
                writer.AddAttribute("selectedstyle", style);
            }

            writer.RenderBeginTag(TagNamespace + ":" + ToolbarTagName);
            writer.WriteLine();

            base.RenderUpLevelPath(writer);

            writer.RenderEndTag();
        }