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