using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Bowin.Web.Controls.Mvc { public class ToolbarButton : BaseControl { public ToolbarButton() { } public string Text { get; set; } public string Icon { get; set; } public string OnClick { get; set; } public override string Render() { StringBuilder html = new StringBuilder(); html.AppendFormat("", string.Join(" ", GetPropertyList().Select(x => string.Concat(x.Key, "=\"", x.Value, "\"")))); if (!string.IsNullOrEmpty(this.Text)) { html.Append(this.Text); } html.Append(""); return html.ToString(); } protected Dictionary GetPropertyList() { Dictionary dictProperty = new Dictionary(); dictProperty.Add("class", "easyui-linkbutton"); if (!string.IsNullOrEmpty(this.ID)) { dictProperty.Add("id", this.ID); } if (!string.IsNullOrEmpty(this.Name)) { dictProperty.Add("name", this.Name); } if (!string.IsNullOrEmpty(this.OnClick)) { dictProperty.Add("href", "javascript:" + this.OnClick); } else { dictProperty.Add("href", "#this"); } #region data-options var dictOptions = new Dictionary(); if (!string.IsNullOrEmpty(this.Icon)) { dictOptions.Add("iconCls", "'" + this.Icon + "'"); } dictOptions.Add("plain", "'true'"); dictProperty.Add("data-options", string.Join(",", dictOptions.Select(x => string.Format("{0}:{1}", x.Key, x.Value)))); #endregion data-options dictProperty.Add("onfocus", "this.blur()"); return dictProperty; } } }