Exemplo n.º 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()
        {
            ToolbarTextBox copy = (ToolbarTextBox)base.Clone();

            copy.TextChanged = this.TextChanged;
            copy._CssWrapper = this._CssWrapper;

            copy._TextBox = new InternalTextBox();
            if (this._IsTrackingVS)
            {
                ((IStateManager)copy).TrackViewState();
            }

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

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

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

            return(copy);
        }
Exemplo n.º 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();
        }