HtmlInputImage.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 override void RenderAttributes(HtmlTextWriter writer)
  21. {
  22. base.RenderAttributes (writer);
  23. // Anything else?
  24. }
  25. protected virtual void OnServerClick(ImageClickEventArgs e){
  26. ImageClickEventHandler handler = (ImageClickEventHandler) Events[EventServerClick];
  27. if (handler != null) handler (this, e);
  28. }
  29. bool IPostBackDataHandler.LoadPostData (string postDataKey,
  30. NameValueCollection postCollection)
  31. {
  32. string postX = postCollection[String.Concat(RenderedName,".x")];
  33. string postY = postCollection[String.Concat(RenderedName,".y")];
  34. if (postX != null && postY != null && postX.Length >= 0 && postY.Length >= 0){
  35. _x = Int32.Parse(postX, CultureInfo.InvariantCulture);
  36. _y = Int32.Parse(postY, CultureInfo.InvariantCulture);
  37. Page.RegisterRequiresRaiseEvent(this);
  38. }
  39. return false;
  40. }
  41. void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
  42. {
  43. if (CausesValidation)
  44. Page.Validate();
  45. OnServerClick (new ImageClickEventArgs(_x, _y));
  46. }
  47. void IPostBackDataHandler.RaisePostDataChangedEvent ()
  48. {
  49. }
  50. public event EventHandler ServerClick{
  51. add{
  52. Events.AddHandler(EventServerClick, value);
  53. }
  54. remove{
  55. Events.RemoveHandler(EventServerClick, value);
  56. }
  57. }
  58. public string Align{
  59. get{
  60. string attr = Attributes["align"];
  61. if (attr != null) return attr;
  62. return String.Empty;
  63. }
  64. set{
  65. Attributes["align"] = AttributeToString(value);
  66. }
  67. }
  68. public string Alt{
  69. get{
  70. string attr = Attributes["alt"];
  71. if (attr != null) return attr;
  72. return String.Empty;
  73. }
  74. set{
  75. Attributes["alt"] = AttributeToString(value);
  76. }
  77. }
  78. public int Border{
  79. get{
  80. string attr = Attributes["border"];
  81. if (attr != null) return Int32.Parse(attr,CultureInfo.InvariantCulture);
  82. return -1;
  83. }
  84. set{
  85. Attributes["border"] = AttributeToString(value);
  86. }
  87. }
  88. public bool CausesValidation{
  89. get{
  90. object causesVal = ViewState["CausesValidation"];
  91. if (causesVal != null) return (Boolean) causesVal;
  92. return true;
  93. }
  94. set{
  95. ViewState["CausesValidation"] = (Boolean) value;
  96. }
  97. }
  98. public string Src{
  99. get{
  100. string attr = Attributes["src"];
  101. if (attr != null) return attr;
  102. return String.Empty;
  103. }
  104. set{
  105. Attributes["src"] = AttributeToString(value);
  106. }
  107. }
  108. } // class HtmlInputImage
  109. } // namespace System.Web.UI.HtmlControls