HtmlInputImage.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. protected override void RenderAttributes(HtmlTextWriter writer){
  25. PreProcessRelativeReference(writer,"src");
  26. if (Page != null && !CausesValidation){
  27. WriteOnClickAttribute(
  28. writer,
  29. false,
  30. true,
  31. CausesValidation == false? Page.Validators.Count > 0: false);
  32. }
  33. RenderAttributes(writer);
  34. }
  35. public bool LoadPostData(string postDataKey, NameValueCollection postCollection){
  36. string postX = postCollection[String.Concat(RenderedName,".x")];
  37. string postY = postCollection[String.Concat(RenderedName,".y")];
  38. if (postX != null && postY != null && postX.Length >= 0 && postY.Length >= 0){
  39. _x = Int32.Parse(postX, CultureInfo.InvariantCulture);
  40. _y = Int32.Parse(postY, CultureInfo.InvariantCulture);
  41. Page.RegisterRequiresRaiseEvent(this);
  42. }
  43. return false;
  44. }
  45. public void RaisePostBackEvent(string eventArgument){
  46. if (CausesValidation){
  47. Page.Validate();
  48. }
  49. OnServerClick(new ImageClickEventArgs(_x,_y));
  50. }
  51. public void RaisePostDataChangedEvent(){}
  52. public event EventHandler 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