Author: igorz
Date: 2006-08-29 11:11:38 -0400 (Tue, 29 Aug 2006)
New Revision: 64512
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/Button.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ButtonTest.cs
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
Log:
implemented 2.0 features
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/Button.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/Button.cs
2006-08-29 14:24:40 UTC (rev 64511)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/Button.cs
2006-08-29 15:11:38 UTC (rev 64512)
@@ -117,16 +117,15 @@
#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;
}
}
@@ -151,25 +150,57 @@
#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);
+#if NET_2_0
+ writer.AddAttribute (HtmlTextWriterAttribute.Type,
UseSubmitBehavior ? "submit" : "button");
+ writer.AddAttribute (HtmlTextWriterAttribute.Name,
UniqueID);
+ writer.AddAttribute (HtmlTextWriterAttribute.Value,
Text);
+ if (!Enabled)
+ writer.AddAttribute
(HtmlTextWriterAttribute.Disabled, "disabled");
+ if (ToolTip.Length > 0)
+ writer.AddAttribute
(HtmlTextWriterAttribute.Title, ToolTip);
+
+ string onclick = OnClientClick;
+ onclick = EnsureEndsWithSemicolon (onclick);
+ if (Attributes ["onclick"] != null) {
+ onclick = EnsureEndsWithSemicolon (onclick +
Attributes ["onclick"]);
+ Attributes.Remove ("onclick");
+ }
+
+ if (Page != null) {
+ bool doValidate = CausesValidation &&
Page.AreValidatorsUplevel ();
+ if (doValidate || PostBackUrl.Length>0) {
+ PostBackOptions options = new
PostBackOptions (this);
+ options.RequiresJavaScriptProtocol =
false;
+ options.ClientSubmit =
!UseSubmitBehavior;
+ options.ActionUrl =
Page.ResolveClientUrl (PostBackUrl);
+ options.PerformValidation = doValidate;
+ options.ValidationGroup =
ValidationGroup;
+ onclick +=
Page.ClientScript.GetPostBackEventReference (options);
+ }
+ else if (!UseSubmitBehavior)
+ onclick +=
Page.ClientScript.GetPostBackEventReference (this, "");
+ }
+
+ if (onclick.Length > 0)
+ writer.AddAttribute
(HtmlTextWriterAttribute.Onclick, onclick);
+#else
writer.AddAttribute (HtmlTextWriterAttribute.Type,
"submit");
writer.AddAttribute (HtmlTextWriterAttribute.Name,
UniqueID);
writer.AddAttribute (HtmlTextWriterAttribute.Value,
Text);
@@ -186,11 +217,18 @@
writer.AddAttribute
(HtmlTextWriterAttribute.Onclick, onclick + csm.GetClientValidationEvent ());
writer.AddAttribute ("language", "javascript");
}
+#endif
base.AddAttributesToRender (writer);
}
#if NET_2_0
+ private static string EnsureEndsWithSemicolon (string onclick) {
+ if (onclick != null && onclick.Length > 0 &&
!onclick.EndsWith (";"))
+ return onclick += ";";
+ return onclick;
+ }
+
[MonoTODO]
protected virtual PostBackOptions GetPostBackOptions ()
{
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2006-08-29 14:24:40 UTC (rev 64511)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2006-08-29 15:11:38 UTC (rev 64512)
@@ -1,3 +1,7 @@
+2006-08-29 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * Button.cs: implemented 2.0 features
+
2006-08-28 Igor Zelmanovich <[EMAIL PROTECTED]>
* Menu.cs: refactoring
Modified:
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ButtonTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ButtonTest.cs
2006-08-29 14:24:40 UTC (rev 64511)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ButtonTest.cs
2006-08-29 15:11:38 UTC (rev 64512)
@@ -36,6 +36,8 @@
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
+using MonoTests.SystemWeb.Framework;
+using MonoTests.stand_alone.WebHarness;
namespace MonoTests.System.Web.UI.WebControls
{
@@ -83,7 +85,13 @@
#if NET_2_0
p.ValidationGroup = "VG1";
+ p.UseSubmitBehavior = false;
+ p.OnClientClick = "ClientClick()";
+ p.PostBackUrl = "PostBackUrl";
Assert.AreEqual (p.ValidationGroup, "VG1", "A3");
+ Assert.AreEqual (false, p.UseSubmitBehavior,
"ViewState_UseSubmitBehavior#original");
+ Assert.AreEqual ("ClientClick()", p.OnClientClick,
"ViewState_OnClientClick#original");
+ Assert.AreEqual ("PostBackUrl", p.PostBackUrl,
"ViewState_PostBackUrl#original");
#endif
object state = p.SaveState ();
@@ -94,6 +102,9 @@
#if NET_2_0
Assert.AreEqual (copy.ValidationGroup, "VG1", "A5");
+ Assert.AreEqual (false, copy.UseSubmitBehavior,
"ViewState_UseSubmitBehavior#copy");
+ Assert.AreEqual ("ClientClick()", p.OnClientClick,
"ViewState_OnClientClick#copy");
+ Assert.AreEqual ("PostBackUrl", p.PostBackUrl,
"ViewState_PostBackUrl#copy");
#endif
}
@@ -124,6 +135,27 @@
string str = tw.ToString ();
Assert.AreEqual (-1, str.IndexOf ("hola"), "hola");
}
+
+#if NET_2_0
+ [Test]
+ public void Button_Render2 () {
+ StringWriter sw = new StringWriter ();
+ HtmlTextWriter tw = new HtmlTextWriter (sw);
+
+ Button b = new Button ();
+ b.ID = "MyButton";
+ b.Text = "Hello";
+ b.UseSubmitBehavior = false;
+ b.Enabled = false;
+ b.ToolTip = "Hello_ToolTip";
+ b.RenderControl (tw);
+
+ string strTarget = "<input type=\"button\"
name=\"MyButton\" value=\"Hello\" disabled=\"disabled\" title=\"Hello_ToolTip\"
/>";
+ string str = sw.ToString();
+ HtmlDiff.AssertAreEqual (strTarget, str,
"Button_Render2");
+ }
+#endif
+
}
}
Modified: trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
2006-08-29 14:24:40 UTC (rev 64511)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/ChangeLog
2006-08-29 15:11:38 UTC (rev 64512)
@@ -1,3 +1,7 @@
+2006-08-29 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * ButtonTest.cs: New tests were added
+
2006-08-27 Igor Zelmanovich <[EMAIL PROTECTED]>
* TreeViewTest.cs: New test was added, removed NotWorking attributes
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches