ToolbarButton.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Bowin.Web.Controls.Mvc
  6. {
  7. public class ToolbarButton : BaseControl
  8. {
  9. public ToolbarButton()
  10. {
  11. }
  12. public string Text { get; set; }
  13. public string Icon { get; set; }
  14. public string OnClick { get; set; }
  15. public override string Render()
  16. {
  17. StringBuilder html = new StringBuilder();
  18. html.AppendFormat("<a {0} >", string.Join(" ", GetPropertyList().Select(x => string.Concat(x.Key, "=\"", x.Value, "\""))));
  19. if (!string.IsNullOrEmpty(this.Text))
  20. {
  21. html.Append(this.Text);
  22. }
  23. html.Append("</a>");
  24. return html.ToString();
  25. }
  26. protected Dictionary<string, string> GetPropertyList()
  27. {
  28. Dictionary<string, string> dictProperty = new Dictionary<string, string>();
  29. dictProperty.Add("class", "easyui-linkbutton");
  30. if (!string.IsNullOrEmpty(this.ID))
  31. {
  32. dictProperty.Add("id", this.ID);
  33. }
  34. if (!string.IsNullOrEmpty(this.Name))
  35. {
  36. dictProperty.Add("name", this.Name);
  37. }
  38. if (!string.IsNullOrEmpty(this.OnClick))
  39. {
  40. dictProperty.Add("href", "javascript:" + this.OnClick);
  41. }
  42. else
  43. {
  44. dictProperty.Add("href", "#this");
  45. }
  46. #region data-options
  47. var dictOptions = new Dictionary<string, string>();
  48. if (!string.IsNullOrEmpty(this.Icon))
  49. {
  50. dictOptions.Add("iconCls", "'" + this.Icon + "'");
  51. }
  52. dictOptions.Add("plain", "'true'");
  53. dictProperty.Add("data-options", string.Join(",", dictOptions.Select(x => string.Format("{0}:{1}", x.Key, x.Value))));
  54. #endregion data-options
  55. dictProperty.Add("onfocus", "this.blur()");
  56. return dictProperty;
  57. }
  58. }
  59. }