HtmlInputImage.cs 2.9 KB

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