Beispiel #1
0
        /// <summary>
        /// <inheritdoc />
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="cssClasses"></param>
        protected override void AddAttributesToRender(IDictionary <HtmlTextWriterAttribute, string> attributes, ICollection <string> cssClasses)
        {
            if (this.IsDefault)
            {
                cssClasses.Add("ui-priority-primary");
            }

            if (!IsScriptNeeded())
            {
                if (this.CssClasses.Length == 0)
                {
                    cssClasses.Add("ui-state-default");
                }
                cssClasses.Add("ui-button");
                cssClasses.Add("ui-widget");
                cssClasses.Add("ui-corner-all");
                if (this.Icon != ButtonIconType.None)
                {
                    if (string.IsNullOrEmpty(this.Text))
                    {
                        cssClasses.Add("ui-button-icon-only");
                    }
                    else
                    {
                        cssClasses.Add("ui-button-text-icon-primary");
                    }
                }
                else
                {
                    cssClasses.Add("ui-button-text-only");
                }
            }

            switch (this.Action)
            {
            case ButtonAction.Submit:
                // Button
                attributes.Add(HtmlTextWriterAttribute.Type, "submit");
                if (!string.IsNullOrEmpty(this.UniqueID))
                {
                    // UniqueID can be null when buton is not part of a page
                    attributes.Add(HtmlTextWriterAttribute.Name, this.UniqueID);
                }
                break;

            case ButtonAction.Reset:
                // A
                attributes.Add(HtmlTextWriterAttribute.Href, this.Page.Request.RawUrl);
                break;


            case ButtonAction.Navigate:
                // A. OnClientClick interpreted as URL
                attributes.Add(HtmlTextWriterAttribute.Href, this.ResolveUrl(this.OnClientClick));
                break;

            case ButtonAction.NewWindow:
                // A
                attributes.Add(HtmlTextWriterAttribute.Href, this.ResolveUrl(this.OnClientClick));

                // Each distinct URL will open in a different window. Same URL will reuse the previously opened window.
                attributes.Add(HtmlTextWriterAttribute.Target, OnClientClick.GetHashCode().ToString());
                break;

            case ButtonAction.None:
                // Button
                attributes.Add(HtmlTextWriterAttribute.Type, "button");
                break;

            default:
                throw new NotImplementedException();
            }


            if (!string.IsNullOrEmpty(this.ToolTip))
            {
                attributes.Add(HtmlTextWriterAttribute.Title, this.ToolTip);
            }
            if (!string.IsNullOrEmpty(this.AccessKey))
            {
                attributes.Add(HtmlTextWriterAttribute.Accesskey, this.AccessKey);
            }
            if (this.TabIndex != 0)
            {
                attributes.Add(HtmlTextWriterAttribute.Tabindex, this.TabIndex.ToString());
            }
            base.AddAttributesToRender(attributes, cssClasses);
        }