Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Habersack <grendel@twistedcode.net>2007-05-08 14:43:25 +0400
committerMarek Habersack <grendel@twistedcode.net>2007-05-08 14:43:25 +0400
commit468f8d970945364bbd6ac81273e07541f9891019 (patch)
tree313f2a4beee0b8c3f6458082e77d084f35366378 /mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs
parentabbda7f3487585ba78d4e03bdbbf9ba5124656b5 (diff)
2007-05-08 Marek Habersack <mhabersack@novell.com>
* HtmlInputButton.cs: button of type 'reset' does not invoke OnServerClick event. 'reset' buttons clear all the controls in the form to their default values. svn path=/trunk/mcs/; revision=76912
Diffstat (limited to 'mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs')
-rw-r--r--mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs108
1 files changed, 106 insertions, 2 deletions
diff --git a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs
index 1defe4341f6..0811ee50b52 100644
--- a/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs
+++ b/mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlInputButton.cs
@@ -28,6 +28,7 @@
using System.ComponentModel;
using System.Globalization;
+using System.Reflection;
using System.Security.Permissions;
namespace System.Web.UI.HtmlControls {
@@ -97,15 +98,118 @@ namespace System.Web.UI.HtmlControls {
void RaisePostBackEventInternal (string eventArgument)
{
- if (CausesValidation)
+ if (CausesValidation) {
#if NET_2_0
Page.Validate (ValidationGroup);
#else
Page.Validate ();
#endif
- OnServerClick (EventArgs.Empty);
+ }
+
+ if (String.Compare (Type, "reset", true, CultureInfo.InvariantCulture) != 0)
+ OnServerClick (EventArgs.Empty);
+ else
+ ResetForm (FindForm ());
}
+ HtmlForm FindForm ()
+ {
+#if NET_2_0
+ return Page.Form;
+#else
+ HtmlForm ret = null;
+ Control p = Parent;
+ while (p != null) {
+ ret = p as HtmlForm;
+ if (ret == null) {
+ p = p.Parent;
+ continue;
+ }
+ return ret;
+ }
+
+ return null;
+#endif
+ }
+
+ void ResetForm (HtmlForm form)
+ {
+ if (form == null || !form.HasControls ())
+ return;
+
+ ResetChildrenValues (form.Controls);
+ }
+
+ void ResetChildrenValues (ControlCollection children)
+ {
+ foreach (Control child in children) {
+ if (child == null)
+ continue;
+
+ if (child.HasControls ())
+ ResetChildrenValues (child.Controls);
+ ResetChildValue (child);
+ }
+ }
+
+ void ResetChildValue (Control child)
+ {
+ Type type = child.GetType ();
+ object[] attributes = type.GetCustomAttributes (false);
+ if (attributes == null || attributes.Length == 0)
+ return;
+
+ string defaultProperty = null;
+ DefaultPropertyAttribute defprop;
+
+ foreach (object attr in attributes) {
+ defprop = attr as DefaultPropertyAttribute;
+ if (defprop == null)
+ continue;
+ defaultProperty = defprop.Name;
+ break;
+ }
+
+ if (defaultProperty == null || defaultProperty.Length == 0)
+ return;
+
+ PropertyInfo pi = null;
+ try {
+ pi = type.GetProperty (defaultProperty,
+ BindingFlags.Instance |
+ BindingFlags.Public |
+ BindingFlags.Static |
+ BindingFlags.IgnoreCase);
+ } catch (Exception) {
+ // ignore
+ }
+ if (pi == null || !pi.CanWrite)
+ return;
+
+ attributes = pi.GetCustomAttributes (false);
+ if (attributes == null || attributes.Length == 0)
+ return;
+
+ DefaultValueAttribute defval = null;
+ object value = null;
+
+ foreach (object attr in attributes) {
+ defval = attr as DefaultValueAttribute;
+ if (defval == null)
+ continue;
+ value = defval.Value;
+ break;
+ }
+
+ if (value == null || pi.PropertyType != value.GetType ())
+ return;
+
+ try {
+ pi.SetValue (child, value, null);
+ } catch (Exception) {
+ // ignore
+ }
+ }
#if NET_2_0
protected virtual void RaisePostBackEvent (string eventArgument)
{