Author: igorz
Date: 2006-09-18 07:52:35 -0400 (Mon, 18 Sep 2006)
New Revision: 65571

Modified:
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/TextBox.cs
Log:
* TextBox.cs: 
make rendering of the onclick attribute to consider ValidationGroup property
Page.Validate() is called when CausesValidation=true


Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2006-09-18 10:46:31 UTC (rev 65570)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2006-09-18 11:52:35 UTC (rev 65571)
@@ -1,3 +1,9 @@
+2006-09-18 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+       * TextBox.cs: 
+       make rendering of the onclick attribute to consider ValidationGroup 
property
+       Page.Validate() is called when CausesValidation=true
+       
 2006-09-14 Igor Zelmanovich <[EMAIL PROTECTED]>
 
        * LinkButton.cs: 

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/TextBox.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/TextBox.cs     
2006-09-18 10:46:31 UTC (rev 65570)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/TextBox.cs     
2006-09-18 11:52:35 UTC (rev 65571)
@@ -29,6 +29,7 @@
 using System.Collections.Specialized;
 using System.ComponentModel;
 using System.Security.Permissions;
+using System.Text;
 
 namespace System.Web.UI.WebControls {
 
@@ -91,9 +92,16 @@
                                break;  
                        }
 
+#if NET_2_0
+                       if (AutoPostBack) {
+                               w.AddAttribute ("onkeypress", "if 
(WebForm_TextBoxKeyHandler(event) == false) return false;");
+                               w.AddAttribute 
(HtmlTextWriterAttribute.Onchange, Page.ClientScript.GetPostBackEventReference 
(GetPostBackOptions ()));
+                       }
+#else          
                        if (AutoPostBack)
                                w.AddAttribute 
(HtmlTextWriterAttribute.Onchange, Page.ClientScript.GetPostBackClientHyperlink 
(this, ""));
-                       
+#endif
+
                        if (ReadOnly)
                                w.AddAttribute 
(HtmlTextWriterAttribute.ReadOnly, "ReadOnly");
 
@@ -117,6 +125,11 @@
                {
                        // What do i do here?
                        base.OnPreRender (e);
+#if NET_2_0
+                       if (AutoPostBack) {
+                               RegisterKeyHandlerClientScript ();
+                       }
+#endif
                }
 
                [MonoTODO ("Am I missing something here")]
@@ -152,6 +165,10 @@
 #endif
                void RaisePostDataChangedEvent ()
                {
+#if NET_2_0
+                       if (CausesValidation)
+                               Page.Validate (ValidationGroup);
+#endif
                        OnTextChanged (EventArgs.Empty);
                }
 
@@ -174,6 +191,45 @@
 #endif         
        
 #if NET_2_0
+               PostBackOptions GetPostBackOptions () {
+                       PostBackOptions options = new PostBackOptions (this);
+                       options.ActionUrl = null;
+                       options.ValidationGroup = null;
+                       options.Argument = "";
+                       options.RequiresJavaScriptProtocol = false;
+                       options.ClientSubmit = true;
+                       options.PerformValidation = CausesValidation && Page != 
null && Page.AreValidatorsUplevel (ValidationGroup);
+                       if (options.PerformValidation)
+                               options.ValidationGroup = ValidationGroup;
+
+                       return options;
+               }
+
+               void RegisterKeyHandlerClientScript () {
+
+                       if (!Page.ClientScript.IsClientScriptBlockRegistered 
(typeof (TextBox), "KeyHandler")) {
+                               StringBuilder script=new StringBuilder();
+                               script.AppendLine ("function 
WebForm_TextBoxKeyHandler(event) {");
+                               script.AppendLine ("\tvar target = 
event.target;");
+                               script.AppendLine ("\tif ((target == null) || 
(typeof(target) == \"undefined\")) target = event.srcElement;");
+                               script.AppendLine ("\tif (event.keyCode == 13) 
{");
+                               script.AppendLine ("\t\tif ((typeof(target) != 
\"undefined\") && (target != null)) {");
+                               script.AppendLine ("\t\t\tif 
(typeof(target.onchange) != \"undefined\") {");
+                               script.AppendLine 
("\t\t\t\ttarget.onchange();");
+                               script.AppendLine ("\t\t\t\tevent.cancelBubble 
= true;");
+                               script.AppendLine ("\t\t\t\tif 
(event.stopPropagation) event.stopPropagation();");
+                               script.AppendLine ("\t\t\t\treturn false;");
+                               script.AppendLine ("\t\t\t}");
+                               script.AppendLine ("\t\t}");
+                               script.AppendLine ("\t}");
+                               script.AppendLine ("\treturn true;");
+                               script.AppendLine ("}");
+                               Page.ClientScript.RegisterClientScriptBlock 
(typeof (TextBox), "KeyHandler", script.ToString(), true);
+                       }
+               }
+#endif
+
+#if NET_2_0
                [DefaultValue (AutoCompleteType.None)]
                [Themeable (false)]
                [MonoTODO]

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to