refactoring: Button, ImageButton and LinkButton are used insted internal DataControlB...
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Button.cs
index 3245aaff7faed34ad886ab83201c7101fdf80d05..6efbe27240acef1818a0de995b5779d58a746bb3 100644 (file)
@@ -89,11 +89,8 @@ namespace System.Web.UI.WebControls {
                [WebCategory ("Behavior")]
 #if NET_2_0
                [Themeable (false)]
-               public virtual
-#else          
-               public
 #endif         
-               string CommandArgument {
+               public string CommandArgument {
                        get {
                                return ViewState.GetString ("CommandArgument", "");
                        }
@@ -107,11 +104,8 @@ namespace System.Web.UI.WebControls {
                [WebCategory ("Behavior")]
 #if NET_2_0
                [Themeable (false)]
-               public virtual
-#else
-               public
 #endif         
-               string CommandName {
+               public string CommandName {
                        get {
                                return ViewState.GetString ("CommandName", "");
                        }
@@ -123,16 +117,15 @@ namespace System.Web.UI.WebControls {
 #if NET_2_0
                [Themeable (false)]
                [DefaultValue ("")]
-               [MonoTODO]
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Behavior")]
                public virtual string OnClientClick 
                {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState.GetString ("OnClientClick", "");
                        }
                        set {
-                               throw new NotImplementedException ();
+                               ViewState ["OnClientClick"] = value;
                        }
                }
 
@@ -144,11 +137,8 @@ namespace System.Web.UI.WebControls {
                [WebCategory ("Appearance")]
 #if NET_2_0
                [Localizable (true)]
-               public virtual
-#else          
-               public
 #endif         
-               string Text {
+               public string Text {
                        get {
                                return ViewState.GetString ("Text", "");
                        }
@@ -160,51 +150,78 @@ namespace System.Web.UI.WebControls {
 #if NET_2_0
                [DefaultValue (true)]
                [Themeable (false)]
-               [MonoTODO]
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Behavior")]
                public virtual bool UseSubmitBehavior 
                {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState.GetBool ("UseSubmitBehavior", true);
                        }
                        set {
-                               throw new NotImplementedException ();
+                               ViewState ["UseSubmitBehavior"] = value;
                        }
                }
 #endif         
 
-               protected override void AddAttributesToRender (HtmlTextWriter writer)
-               {
+               protected override void AddAttributesToRender (HtmlTextWriter writer) {
                        if (Page != null)
                                Page.VerifyRenderingInServerForm (this);
 
-                       writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
 #if NET_2_0
-                       if (ID != null)
-                               writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
+                       writer.AddAttribute (HtmlTextWriterAttribute.Type, UseSubmitBehavior ? "submit" : "button");
+                       writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
+                       writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
+
+                       string onclick = OnClientClick;
+                       onclick = ClientScriptManager.EnsureEndsWithSemicolon (onclick);
+                       if (Attributes ["onclick"] != null) {
+                               onclick = ClientScriptManager.EnsureEndsWithSemicolon (onclick + Attributes ["onclick"]);
+                               Attributes.Remove ("onclick");
+                       }
+
+                       if (Page != null) {
+                               PostBackOptions options = GetPostBackOptions ();
+                               onclick += Page.ClientScript.GetPostBackEventReference (options);
+                       }
+
+                       if (onclick.Length > 0)
+                               writer.AddAttribute (HtmlTextWriterAttribute.Onclick, onclick);
 #else
+                       writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
                        writer.AddAttribute (HtmlTextWriterAttribute.Name, UniqueID);
-#endif
                        writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
 
                        if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
                                string onclick = Attributes["onclick"];
-                               if (onclick != null)
+                               if (onclick != null) {
                                        Attributes.Remove("onclick");
+                                       int len = onclick.Length;
+                                       if (len > 0 && onclick[len - 1] != ';')
+                                               onclick += ";";
+                               }
                                ClientScriptManager csm = new ClientScriptManager (Page);
                                writer.AddAttribute (HtmlTextWriterAttribute.Onclick, onclick + csm.GetClientValidationEvent ());
                                writer.AddAttribute ("language", "javascript");
                        }
+#endif
 
                        base.AddAttributesToRender (writer);
                }
 
 #if NET_2_0
-               [MonoTODO]
-               protected virtual PostBackOptions GetPostBackOptions ()
+               protected virtual PostBackOptions GetPostBackOptions () 
                {
-                       throw new NotImplementedException ();
+                       PostBackOptions options = new PostBackOptions (this);
+                       options.ActionUrl = (PostBackUrl.Length > 0 ? Page.ResolveClientUrl (PostBackUrl) : null);
+                       options.ValidationGroup = null;
+                       options.Argument = "";
+                       options.RequiresJavaScriptProtocol = false;
+                       options.ClientSubmit = !UseSubmitBehavior;
+                       options.PerformValidation = CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup);
+                       if (options.PerformValidation)
+                               options.ValidationGroup = ValidationGroup;
+
+                       return options;
                }
 #endif         
 
@@ -287,13 +304,12 @@ namespace System.Web.UI.WebControls {
                [Editor ("System.Web.UI.Design.UrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
                [Themeable (false)]
                [UrlProperty("*.aspx")]
-               [MonoTODO]
-               public string PostBackUrl {
+               public virtual string PostBackUrl {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState.GetString ("PostBackUrl", "");
                        }
                        set {
-                               throw new NotImplementedException ();
+                               ViewState ["PostBackUrl"] = value;
                        }
                }
 
@@ -301,7 +317,7 @@ namespace System.Web.UI.WebControls {
                [Themeable (false)]
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Behavior")]
-               public string ValidationGroup {
+               public virtual string ValidationGroup {
                        get {
                                return ViewState.GetString ("ValidationGroup", "");
                        }