HtmlInputImage.cs 3.2 KB

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