2
0

HtmlInputImage.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. public event ImageClickEventHandler ServerClick{
  53. add{
  54. Events.AddHandler(EventServerClick, value);
  55. }
  56. remove{
  57. Events.RemoveHandler(EventServerClick, value);
  58. }
  59. }
  60. public string Align{
  61. get{
  62. string attr = Attributes["align"];
  63. if (attr != null) return attr;
  64. return String.Empty;
  65. }
  66. set{
  67. Attributes["align"] = AttributeToString(value);
  68. }
  69. }
  70. public string Alt{
  71. get{
  72. string attr = Attributes["alt"];
  73. if (attr != null) return attr;
  74. return String.Empty;
  75. }
  76. set{
  77. Attributes["alt"] = AttributeToString(value);
  78. }
  79. }
  80. public int Border{
  81. get{
  82. string attr = Attributes["border"];
  83. if (attr != null) return Int32.Parse(attr,CultureInfo.InvariantCulture);
  84. return -1;
  85. }
  86. set{
  87. Attributes["border"] = AttributeToString(value);
  88. }
  89. }
  90. public bool CausesValidation{
  91. get{
  92. object causesVal = ViewState["CausesValidation"];
  93. if (causesVal != null) return (Boolean) causesVal;
  94. return true;
  95. }
  96. set{
  97. ViewState["CausesValidation"] = (Boolean) value;
  98. }
  99. }
  100. public string Src{
  101. get{
  102. string attr = Attributes["src"];
  103. if (attr != null) return attr;
  104. return String.Empty;
  105. }
  106. set{
  107. Attributes["src"] = AttributeToString(value);
  108. }
  109. }
  110. } // class HtmlInputImage
  111. } // namespace System.Web.UI.HtmlControls