HtmlInputImage.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. namespace System.Web.UI.HtmlControls{
  10. public class HtmlInputImage : HtmlInputControl, IPostBackEventHandler, IPostBackDataHandler{
  11. private static readonly object EventServerChange;
  12. private int _x, _y;
  13. public HtmlInputImage(): base("image"){}
  14. protected void OnPreRender(EventArgs e){
  15. if (Page != null && !Disabled){
  16. Page.RegisterRequiresPostBack(this);
  17. }
  18. }
  19. protected void OnServerClick(ImageClickEventArgs e){
  20. ImageClickEventHandler handler = (ImageClickEventHandler) Events[EventServerClick];
  21. if (handler != null){
  22. handler.Invoke(this, e);
  23. }
  24. }
  25. protected override void RenderAttributes(HtmlTextWriter writer){
  26. PreProcessRelativeReferenceAttribute(writer,"src");
  27. if (Page != null && !CausesValidation){
  28. Util.WriteOnClickAttribute(
  29. writer,
  30. this,
  31. false,
  32. true,
  33. CausesValidation == false? Page.Validators.Count > 0: false);
  34. }
  35. RenderAttributes(writer);
  36. }
  37. public bool LoadPostData(string postDataKey, NameValueCollection postCollection){
  38. string postX = postCollection[String.Concat(RenderedNameAttribute,".x")];
  39. string postY = postCollection[String.Concat(RenderedNameAttribute,".y")];
  40. if (postX != null && postY != null && postX.Length >= 0 && postY.Length >= 0){
  41. _x = Int32.Parse(postX, CultureInfo.InvariantCulture);
  42. _y = Int32.Parse(postY, CultureInfo.InvariantCulture);
  43. Page.RegisterRequiresRaiseEvent(this);
  44. }
  45. return false;
  46. }
  47. public override void RaisePostDataChangedEvent(){}
  48. public override IPostBackEventHandler RaisePostBackEvent(string eventArgument){
  49. if (CausesValidation != null){
  50. Page.Validate();
  51. }
  52. OnServerClick(new ImageClickEventArgs(_x, _y));
  53. }
  54. public event EventHandler ServerClick{
  55. add{
  56. Events.AddHandler(EventServerClick, value);
  57. }
  58. remove{
  59. Events.RemoveHandler(EventServerClick, value);
  60. }
  61. }
  62. public string Align{
  63. get{
  64. string attr = Attributes["align"];
  65. if (attr != null){
  66. return attr;
  67. }
  68. return "";
  69. }
  70. set{
  71. Attributes["align"] = MapStringAttributeToString(value);
  72. }
  73. }
  74. public string Alt{
  75. get{
  76. string attr = Attributes["alt"];
  77. if (attr != null){
  78. return attr;
  79. }
  80. return "";
  81. }
  82. set{
  83. Attributes["alt"] = MapStringAttributeToString(value);
  84. }
  85. }
  86. public int Border{
  87. get{
  88. string attr = Attributes["border"];
  89. if (attr != null){
  90. return Int32.Parse(attr,CultureInfo.InvariantCulture);
  91. }
  92. return -1;
  93. }
  94. set{
  95. Attributes["border"] = MapIntegerAttributeToString(value);
  96. }
  97. }
  98. public bool CausesValidation{
  99. get{
  100. object causesVal = ViewState["CausesValidation"];
  101. if (causesVal != null){
  102. return (Boolean) causesVal;
  103. }
  104. return true;
  105. }
  106. set{
  107. ViewState["CausesValidation"] = (Boolean) value;
  108. }
  109. }
  110. public string Src{
  111. get{
  112. string attr = Attributes["src"];
  113. if (attr != null){
  114. return attr;
  115. }
  116. return "";
  117. }
  118. set{
  119. Attributes["src"] = MapStringAttributeToString(value);
  120. }
  121. }
  122. public event ServerClick;
  123. } // class HtmlInputImage
  124. } // namespace System.Web.UI.HtmlControls