Merge branch 'master' of github.com:mono/mono
[mono.git] / mcs / class / System.Web / System.Web.UI / PostBackOptions.cs
1 //
2 // System.Web.UI.PostBackOptions.cs
3 //
4 // Authors:
5 //      Sanjay Gupta (gsanjay@novell.com)
6 //
7 // Copyright (C) 2004-2010 Novell, Inc (http://www.novell.com)
8 //
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.ComponentModel;
32
33 namespace System.Web.UI
34 {
35         public sealed class PostBackOptions
36         {
37                 Control control;
38                 string argument;
39                 string actionUrl;
40                 bool autoPostBack;
41                 bool requiresJavaScriptProtocol;
42                 bool trackFocus;
43                 bool clientSubmit;
44                 bool performValidation;
45                 string validationGroup;
46
47                 public PostBackOptions (Control targetControl)
48                         : this (targetControl, null, null, false, false, false, true, false, null)
49                 {
50                 }
51
52                 public PostBackOptions (Control targetControl, string argument)
53                         : this (targetControl, argument, null, false, false, false, true, false, null)
54                 {
55                 }
56
57                 public PostBackOptions (Control targetControl, string argument, string actionUrl, bool autoPostBack,
58                                         bool requiresJavaScriptProtocol, bool trackFocus, bool clientSubmit,
59                                         bool performValidation, string validationGroup)
60                 {
61                         if (targetControl == null)
62                                 throw new ArgumentNullException ("targetControl");
63                         this.control = targetControl;
64                         this.argument = argument;
65                         this.actionUrl = actionUrl;
66                         this.autoPostBack = autoPostBack;
67                         this.requiresJavaScriptProtocol = requiresJavaScriptProtocol;
68                         this.trackFocus = trackFocus;
69                         this.clientSubmit = clientSubmit;
70                         this.performValidation = performValidation;
71                         this.validationGroup = validationGroup;
72                 }
73
74                 [DefaultValue ("")]
75                 public string ActionUrl {
76                         get { return actionUrl; }
77                         set { actionUrl = value; }
78                 }
79
80                 [DefaultValue ("")]
81                 public string Argument {
82                         get { return  argument; }
83                         set { argument = value; }
84                 }
85
86                 [MonoTODO ("Implement support for this in Page")]
87                 [DefaultValue (false)]
88                 public bool AutoPostBack {
89                         get { return autoPostBack; }
90                         set { autoPostBack = value; }
91                 }
92
93                 [DefaultValue (true)]
94                 public bool ClientSubmit {
95                         get { return clientSubmit; }
96                         set { clientSubmit = value; }
97                 }
98                 
99                 [DefaultValue (false)]
100                 public bool PerformValidation {
101                         get { return performValidation; }
102                         set { performValidation = value; }
103                 }
104
105                 [DefaultValue (true)]
106                 public bool RequiresJavaScriptProtocol {
107                         get { return requiresJavaScriptProtocol; }
108                         set { requiresJavaScriptProtocol = value; }
109                 }
110
111                 [DefaultValue (null)]
112                 public Control TargetControl {
113                         get { return control; }
114                 }
115
116                 [MonoTODO ("Implement support for this in Page")]
117                 [DefaultValue (false)]
118                 public bool TrackFocus {
119                         get { return trackFocus; }
120                         set { trackFocus = value; }
121                 }
122
123                 [MonoTODO ("Implement support for this in Page")]
124                 [DefaultValue ("")]
125                 public string ValidationGroup {
126                         get { return validationGroup; }
127                         set { validationGroup = value; }
128                 }
129                 
130                 // Returns true if some of these options must be handled by
131                 // client script.
132                 internal bool RequiresSpecialPostBack {
133                         get { 
134                                 return actionUrl != null || 
135                                                 validationGroup != null || 
136                                                 trackFocus || 
137                                                 autoPostBack || 
138                                                 argument != null;
139                         }
140                 }
141         }
142 }