HtmlCommandAdapter.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * Project : Mono
  3. * Namespace : System.Web.UI.MobileControls.Adapters
  4. * Class : HtmlCommandAdapter
  5. * Author : Gaurav Vaish
  6. *
  7. * Copyright : 2003 with Gaurav Vaish, and with
  8. * Ximian Inc
  9. */
  10. using System;
  11. using System.Collections.Specialized;
  12. using System.Web.Mobile;
  13. using System.Web.UI.MobileControls;
  14. namespace System.Web.UI.MobileControls.Adapters
  15. {
  16. public class HtmlCommandAdapter : HtmlControlAdapter
  17. {
  18. public HtmlCommandAdapter() : base()
  19. {
  20. }
  21. protected new Command Control
  22. {
  23. get
  24. {
  25. return base.Control as Command;
  26. }
  27. }
  28. public override bool LoadPostData(string postKey,
  29. NameValueCollection data,
  30. object privateControlData, out bool dataChanged)
  31. {
  32. dataChanged = false;
  33. bool retVal = false;
  34. if(Control != null)
  35. {
  36. string id = Control.UniqueID;
  37. string ctrl = data[id + ".x"];
  38. string evnt = data[id + ".y"];
  39. if(ctrl != null && evnt != null && ctrl.Length > 0 && evnt.Length > 0)
  40. {
  41. dataChanged = true;
  42. retVal = true;
  43. }
  44. }
  45. return retVal;
  46. }
  47. public override void Render(HtmlMobileTextWriter writer)
  48. {
  49. bool supportsImgSbt = false;
  50. bool supportsJavascript = false;
  51. Form mobileForm = null;
  52. if(Control != null)
  53. {
  54. if(Control.ImageUrl != String.Empty && Device.SupportsImageSubmit)
  55. {
  56. supportsImgSbt = true;
  57. if(Control.Format == CommandFormat.Link)
  58. {
  59. if(Device.JavaScript)
  60. {
  61. supportsJavascript = true;
  62. }
  63. }
  64. }
  65. }
  66. if(supportsJavascript)
  67. {
  68. writer.EnterStyle(Style);
  69. mobileForm = Control.Form;
  70. if(mobileForm.Action.Length > 0)
  71. {
  72. writer.Write("<a href=\"javascript:document.");
  73. writer.Write(mobileForm.ClientID);
  74. writer.Write(".submit()\"");
  75. base.AddAttributes(writer);
  76. writer.Write(">");
  77. writer.WriteText(Control.Text, false);
  78. writer.WriteEndTag("a");
  79. } else
  80. {
  81. base.RenderBeginLink(writer, Constants.FormIDPrefix + mobileForm.UniqueID);
  82. writer.WriteText(Control.Text, true);
  83. base.RenderEndLink(writer);
  84. }
  85. writer.ExitStyle(Style, Control.BreakAfter);
  86. } else
  87. {
  88. writer.EnterLayout(Style);
  89. writer.WriteBeginTag("input");
  90. writer.WriteAttribute("name", Control.UniqueID);
  91. if(supportsImgSbt)
  92. {
  93. writer.WriteAttribute("type", "image");
  94. writer.WriteAttribute("src", Control.ResolveUrl(Control.ImageUrl));
  95. writer.WriteAttribute("alt", Control.Text);
  96. } else
  97. {
  98. writer.WriteAttribute("type", "submit");
  99. writer.Write("value=\"");
  100. writer.WriteText(Control.Text, true);
  101. }
  102. writer.Write("\"");
  103. base.AddAttributes(writer);
  104. writer.Write("/>");
  105. writer.ExitLayout(Style, Control.BreakAfter);
  106. }
  107. }
  108. }
  109. }