1 /* System.Web.UI.HtmlControls
3 * Leen Toelen (toelen@hotmail.com)
7 using System
.ComponentModel
;
8 using System
.Globalization
;
12 namespace System
.Web
.UI
.HtmlControls
{
14 [DefaultEvent("ServerClick")]
15 public class HtmlInputButton
: HtmlInputControl
, IPostBackEventHandler
{
17 private static readonly object EventServerClick
= new object ();
19 public HtmlInputButton(): base ("button")
23 public HtmlInputButton(string type
): base(type
){}
25 protected override void OnPreRender (EventArgs e
)
28 if (Page
!= null && Events
[EventServerClick
] != null)
29 Page
.RequiresPostBackScript ();
32 protected override void RenderAttributes (HtmlTextWriter writer
)
34 if (Page
!= null && CausesValidation
) {
36 if (String
.Compare (type
, "button", true) == 0 || String
.Compare (type
, "submit", true) == 0) {
37 string script
= Page
.GetPostBackClientEvent (this, String
.Empty
);
39 ((String
.Compare (type
, "button", true) == 0 && Events
[EventServerClick
] != null )||
40 (String
.Compare (type
, "submit", true) == 0 && Page
.Validators
.Count
> 0))){
41 AttributeCollection coll
= Attributes
;
42 if (coll
["language"] != null)
43 coll
.Remove ("language");
44 writer
.WriteAttribute ("language", "javascript");
47 if ((onclick
= coll
["onclick"]) != null) {
48 script
= onclick
+ " " + script
;
49 coll
.Remove ("onclick");
52 writer
.WriteAttribute ("onclick", script
);
57 base.RenderAttributes (writer
);
60 protected virtual void OnServerClick(EventArgs e
){
61 EventHandler handler
= (EventHandler
) Events
[EventServerClick
];
67 void IPostBackEventHandler
.RaisePostBackEvent (string eventArgument
)
69 if(CausesValidation
== true){
72 OnServerClick(EventArgs
.Empty
);
75 [WebCategory("Action")]
76 [WebSysDescription("Fires when the control is clicked.")]
77 public event EventHandler ServerClick
{
79 Events
.AddHandler(EventServerClick
, value);
82 Events
.RemoveHandler(EventServerClick
, value);
87 [WebCategory("Behavior")]
88 public bool CausesValidation
{
90 object causesVal
= ViewState
["CausesValidation"];
91 if (causesVal
!= null){
92 return (Boolean
) causesVal
;
97 ViewState
["CausesValidation"] = (Boolean
) value;
101 } // end of System.Web.UI.HtmlControls.HtmlInputButton
102 } // namespace System.Web.UI.HtmlControls