HtmlInputImage.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* System.Web.UI.HtmlControls
  2. * Authors
  3. * Leen Toelen ([email protected])
  4. */
  5. using System;
  6. using System.Collections.Specialized;
  7. using System.ComponentModel;
  8. using System.Globalization;
  9. using System.Web;
  10. using System.Web.UI;
  11. namespace System.Web.UI.HtmlControls{
  12. [DefaultEvent("ServerClick")]
  13. public class HtmlInputImage : HtmlInputControl, IPostBackEventHandler, IPostBackDataHandler{
  14. private static readonly object EventServerClick = new object ();
  15. private int _x, _y;
  16. public HtmlInputImage(): base("image"){}
  17. protected override void OnPreRender(EventArgs e){
  18. if (Page != null && !Disabled){
  19. Page.RegisterRequiresPostBack(this);
  20. }
  21. }
  22. protected override void RenderAttributes(HtmlTextWriter writer)
  23. {
  24. base.RenderAttributes (writer);
  25. // Anything else?
  26. }
  27. protected virtual void OnServerClick(ImageClickEventArgs e){
  28. ImageClickEventHandler handler = (ImageClickEventHandler) Events[EventServerClick];
  29. if (handler != null) handler (this, e);
  30. }
  31. bool IPostBackDataHandler.LoadPostData (string postDataKey,
  32. NameValueCollection postCollection)
  33. {
  34. string postX = postCollection[String.Concat(RenderedName,".x")];
  35. string postY = postCollection[String.Concat(RenderedName,".y")];
  36. if (postX != null && postY != null && postX.Length >= 0 && postY.Length >= 0){
  37. _x = Int32.Parse(postX, CultureInfo.InvariantCulture);
  38. _y = Int32.Parse(postY, CultureInfo.InvariantCulture);
  39. Page.RegisterRequiresRaiseEvent(this);
  40. }
  41. return false;
  42. }
  43. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  44. {
  45. if (CausesValidation)
  46. Page.Validate();
  47. OnServerClick (new ImageClickEventArgs(_x, _y));
  48. }
  49. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  50. {
  51. }
  52. [WebCategory("Action")]
  53. [WebSysDescription("Fires when the image is clicked.")]
  54. public event ImageClickEventHandler ServerClick{
  55. add{
  56. Events.AddHandler(EventServerClick, value);
  57. }
  58. remove{
  59. Events.RemoveHandler(EventServerClick, value);
  60. }
  61. }
  62. [DefaultValue("")]
  63. [WebCategory("Appearance")]
  64. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  65. public string Align{
  66. get{
  67. string attr = Attributes["align"];
  68. if (attr != null) return attr;
  69. return String.Empty;
  70. }
  71. set{
  72. Attributes["align"] = AttributeToString(value);
  73. }
  74. }
  75. [DefaultValue("")]
  76. [WebCategory("Appearance")]
  77. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  78. public string Alt{
  79. get{
  80. string attr = Attributes["alt"];
  81. if (attr != null) return attr;
  82. return String.Empty;
  83. }
  84. set{
  85. Attributes["alt"] = AttributeToString(value);
  86. }
  87. }
  88. [DefaultValue("")]
  89. [WebCategory("Appearance")]
  90. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  91. public int Border{
  92. get{
  93. string attr = Attributes["border"];
  94. if (attr != null) return Int32.Parse(attr,CultureInfo.InvariantCulture);
  95. return -1;
  96. }
  97. set{
  98. Attributes["border"] = AttributeToString(value);
  99. }
  100. }
  101. [DefaultValue(true)]
  102. [WebCategory("Behavior")]
  103. public bool CausesValidation{
  104. get{
  105. object causesVal = ViewState["CausesValidation"];
  106. if (causesVal != null) return (Boolean) causesVal;
  107. return true;
  108. }
  109. set{
  110. ViewState["CausesValidation"] = (Boolean) value;
  111. }
  112. }
  113. [DefaultValue("")]
  114. [WebCategory("Appearance")]
  115. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  116. public string Src{
  117. get{
  118. string attr = Attributes["src"];
  119. if (attr != null) return attr;
  120. return String.Empty;
  121. }
  122. set{
  123. Attributes["src"] = AttributeToString(value);
  124. }
  125. }
  126. } // class HtmlInputImage
  127. } // namespace System.Web.UI.HtmlControls