2 // System.Web.UI.WebControls.CommandField.cs
\r
5 // Lluis Sanchez Gual (lluis@novell.com)
\r
7 // (C) 2005 Novell, Inc (http://www.novell.com)
\r
11 // Permission is hereby granted, free of charge, to any person obtaining
\r
12 // a copy of this software and associated documentation files (the
\r
13 // "Software"), to deal in the Software without restriction, including
\r
14 // without limitation the rights to use, copy, modify, merge, publish,
\r
15 // distribute, sublicense, and/or sell copies of the Software, and to
\r
16 // permit persons to whom the Software is furnished to do so, subject to
\r
17 // the following conditions:
\r
19 // The above copyright notice and this permission notice shall be
\r
20 // included in all copies or substantial portions of the Software.
\r
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
32 using System.Collections;
\r
33 using System.Collections.Specialized;
\r
34 using System.Web.UI;
\r
35 using System.ComponentModel;
\r
36 using System.Security.Permissions;
\r
38 namespace System.Web.UI.WebControls {
\r
40 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
\r
41 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
\r
42 public class CommandField : ButtonFieldBase
\r
44 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
45 [UrlPropertyAttribute]
\r
46 [DefaultValueAttribute ("")]
\r
47 [WebSysDescription ("")]
\r
48 [WebCategoryAttribute ("Appearance")]
\r
49 public virtual string CancelImageUrl {
\r
50 get { return ViewState.GetString ("CancelImageUrl", ""); }
\r
52 ViewState ["CancelImageUrl"] = value;
\r
57 [LocalizableAttribute (true)]
\r
58 [WebSysDescription ("")]
\r
59 [WebCategoryAttribute ("Appearance")]
\r
60 public virtual string CancelText {
\r
61 get { return ViewState.GetString ("CancelText", "Cancel"); }
\r
63 ViewState ["CancelText"] = value;
\r
68 [DefaultValueAttribute (true)]
\r
69 public override bool CausesValidation {
\r
70 get { return ViewState.GetBool ("CausesValidation", true); }
\r
72 ViewState ["CausesValidation"] = value;
\r
77 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
78 [UrlPropertyAttribute]
\r
79 [DefaultValueAttribute ("")]
\r
80 [WebSysDescription ("")]
\r
81 [WebCategoryAttribute ("Appearance")]
\r
82 public virtual string DeleteImageUrl {
\r
83 get { return ViewState.GetString ("DeleteImageUrl", ""); }
\r
85 ViewState ["DeleteImageUrl"] = value;
\r
90 [LocalizableAttribute (true)]
\r
91 [WebSysDescription ("")]
\r
92 [WebCategoryAttribute ("Appearance")]
\r
93 public virtual string DeleteText {
\r
94 get { return ViewState.GetString ("DeleteText", "Delete"); }
\r
96 ViewState ["DeleteText"] = value;
\r
101 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
102 [UrlPropertyAttribute]
\r
103 [DefaultValueAttribute ("")]
\r
104 [WebSysDescription ("")]
\r
105 [WebCategoryAttribute ("Appearance")]
\r
106 public virtual string EditImageUrl {
\r
107 get { return ViewState.GetString ("EditImageUrl", ""); }
\r
109 ViewState ["EditImageUrl"] = value;
\r
114 [LocalizableAttribute (true)]
\r
115 [WebSysDescription ("")]
\r
116 [WebCategoryAttribute ("Appearance")]
\r
117 public virtual string EditText {
\r
118 get { return ViewState.GetString ("EditText", "Edit"); }
\r
120 ViewState ["EditText"] = value;
\r
125 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
126 [UrlPropertyAttribute]
\r
127 [DefaultValueAttribute ("")]
\r
128 [WebSysDescription ("")]
\r
129 [WebCategoryAttribute ("Appearance")]
\r
130 public virtual string InsertImageUrl {
\r
131 get { return ViewState.GetString ("InsertImageUrl", ""); }
\r
133 ViewState ["InsertImageUrl"] = value;
\r
138 [LocalizableAttribute (true)]
\r
139 [WebSysDescription ("")]
\r
140 [WebCategoryAttribute ("Appearance")]
\r
141 public virtual string InsertText {
\r
142 get { return ViewState.GetString ("InsertText", "Insert"); }
\r
144 ViewState ["InsertText"] = value;
\r
149 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
150 [UrlPropertyAttribute]
\r
151 [DefaultValueAttribute ("")]
\r
152 [WebSysDescription ("")]
\r
153 [WebCategoryAttribute ("Appearance")]
\r
154 public virtual string NewImageUrl {
\r
155 get { return ViewState.GetString ("NewImageUrl", ""); }
\r
157 ViewState ["NewImageUrl"] = value;
\r
162 [LocalizableAttribute (true)]
\r
163 [WebSysDescription ("")]
\r
164 [WebCategoryAttribute ("Appearance")]
\r
165 public virtual string NewText {
\r
166 get { return ViewState.GetString ("NewText", "New"); }
\r
168 ViewState ["NewText"] = value;
\r
173 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
174 [UrlPropertyAttribute]
\r
175 [DefaultValueAttribute ("")]
\r
176 [WebSysDescription ("")]
\r
177 [WebCategoryAttribute ("Appearance")]
\r
178 public virtual string SelectImageUrl {
\r
179 get { return ViewState.GetString ("SelectImageUrl", ""); }
\r
181 ViewState ["SelectImageUrl"] = value;
\r
186 [LocalizableAttribute (true)]
\r
187 [WebSysDescription ("")]
\r
188 [WebCategoryAttribute ("Appearance")]
\r
189 public virtual string SelectText {
\r
190 get { return ViewState.GetString ("SelectText", "Select"); }
\r
192 ViewState ["SelectText"] = value;
\r
197 [DefaultValueAttribute (true)]
\r
198 [WebSysDescription ("")]
\r
199 [WebCategoryAttribute ("Behavior")]
\r
200 public virtual bool ShowCancelButton {
\r
201 get { return ViewState.GetBool ("ShowCancelButton", true); }
\r
203 ViewState ["ShowCancelButton"] = value;
\r
208 [DefaultValueAttribute (false)]
\r
209 [WebSysDescription ("")]
\r
210 [WebCategoryAttribute ("Behavior")]
\r
211 public virtual bool ShowDeleteButton {
\r
212 get { return ViewState.GetBool ("ShowDeleteButton", false); }
\r
214 ViewState ["ShowDeleteButton"] = value;
\r
219 [DefaultValueAttribute (false)]
\r
220 [WebSysDescription ("")]
\r
221 [WebCategoryAttribute ("Behavior")]
\r
222 public virtual bool ShowEditButton {
\r
223 get { return ViewState.GetBool ("ShowEditButton", false); }
\r
225 ViewState ["ShowEditButton"] = value;
\r
230 [DefaultValueAttribute (false)]
\r
231 [WebSysDescription ("")]
\r
232 [WebCategoryAttribute ("Behavior")]
\r
233 public virtual bool ShowSelectButton {
\r
234 get { return ViewState.GetBool ("ShowSelectButton", false); }
\r
236 ViewState ["ShowSelectButton"] = value;
\r
241 [DefaultValueAttribute (false)]
\r
242 [WebSysDescription ("")]
\r
243 [WebCategoryAttribute ("Behavior")]
\r
244 public virtual bool ShowInsertButton {
\r
245 get { return ViewState.GetBool ("ShowInsertButton", false); }
\r
247 ViewState ["ShowInsertButton"] = value;
\r
252 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
\r
253 [UrlPropertyAttribute]
\r
254 [DefaultValueAttribute ("")]
\r
255 [WebSysDescription ("")]
\r
256 [WebCategoryAttribute ("Appearance")]
\r
257 public virtual string UpdateImageUrl {
\r
258 get { return ViewState.GetString ("UpdateImageUrl", ""); }
\r
260 ViewState ["UpdateImageUrl"] = value;
\r
265 [LocalizableAttribute (true)]
\r
266 [WebSysDescription ("")]
\r
267 [WebCategoryAttribute ("Appearance")]
\r
268 public virtual string UpdateText {
\r
269 get { return ViewState.GetString ("UpdateText", "Update"); }
\r
271 ViewState ["UpdateText"] = value;
\r
276 public override void InitializeCell (DataControlFieldCell cell,
\r
277 DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
\r
279 string index = rowIndex.ToString ();
\r
281 if (cellType == DataControlCellType.DataCell)
\r
283 if ((rowState & DataControlRowState.Edit) != 0) {
\r
284 if (ShowEditButton) {
\r
285 cell.Controls.Add (CreateButton (UpdateText, UpdateImageUrl, DataControlCommands.UpdateCommandName, index));
\r
286 if (ShowCancelButton) {
\r
287 AddSeparator (cell);
\r
288 cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
\r
291 } else if ((rowState & DataControlRowState.Insert) != 0) {
\r
292 if (ShowInsertButton) {
\r
293 cell.Controls.Add (CreateButton (InsertText, InsertImageUrl, DataControlCommands.InsertCommandName, index));
\r
294 if (ShowCancelButton) {
\r
295 AddSeparator (cell);
\r
296 cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
\r
300 if (ShowEditButton) {
\r
301 AddSeparator (cell);
\r
302 cell.Controls.Add (CreateButton (EditText, EditImageUrl, DataControlCommands.EditCommandName, index));
\r
304 if (ShowDeleteButton) {
\r
305 AddSeparator (cell);
\r
306 cell.Controls.Add (CreateButton (DeleteText, DeleteImageUrl, DataControlCommands.DeleteCommandName, index));
\r
308 if (ShowInsertButton) {
\r
309 AddSeparator (cell);
\r
310 cell.Controls.Add (CreateButton (NewText, NewImageUrl, DataControlCommands.NewCommandName, index));
\r
312 if (ShowSelectButton) {
\r
313 AddSeparator (cell);
\r
314 cell.Controls.Add (CreateButton (SelectText, SelectImageUrl, DataControlCommands.SelectCommandName, index));
\r
318 base.InitializeCell (cell, cellType, rowState, rowIndex);
\r
321 Control CreateButton (string text, string image, string command, string arg)
\r
323 IDataControlButton c = DataControlButton.CreateButton (ButtonType, Control, text, image, command, arg, false);
\r
324 if (CausesValidation) {
\r
325 if (command == DataControlCommands.UpdateCommandName || command == DataControlCommands.InsertCommandName) {
\r
326 c.Container = null;
\r
327 c.CausesValidation = true;
\r
328 c.ValidationGroup = ValidationGroup;
\r
334 void AddSeparator (DataControlFieldCell cell)
\r
336 if (cell.Controls.Count > 0) {
\r
337 Literal lit = new Literal ();
\r
338 lit.Text = " ";
\r
339 cell.Controls.Add (lit);
\r
343 protected override DataControlField CreateField ()
\r
345 return new CommandField ();
\r
348 protected override void CopyProperties (DataControlField newField)
\r
350 base.CopyProperties (newField);
\r
351 CommandField field = (CommandField) newField;
\r
352 field.CancelImageUrl = CancelImageUrl;
\r
353 field.CancelText = CancelText;
\r
354 field.DeleteImageUrl = DeleteImageUrl;
\r
355 field.DeleteText = DeleteText;
\r
356 field.EditImageUrl = EditImageUrl;
\r
357 field.EditText = EditText;
\r
358 field.InsertImageUrl = InsertImageUrl;
\r
359 field.InsertText = InsertText;
\r
360 field.NewImageUrl = NewImageUrl;
\r
361 field.NewText = NewText;
\r
362 field.SelectImageUrl = SelectImageUrl;
\r
363 field.SelectText = SelectText;
\r
364 field.ShowCancelButton = ShowCancelButton;
\r
365 field.ShowDeleteButton = ShowDeleteButton;
\r
366 field.ShowEditButton = ShowEditButton;
\r
367 field.ShowSelectButton = ShowSelectButton;
\r
368 field.ShowInsertButton = ShowInsertButton;
\r
369 field.UpdateImageUrl = UpdateImageUrl;
\r
370 field.UpdateText = UpdateText;
\r
373 public override void ValidateSupportsCallback ()
\r
375 if (ShowSelectButton)
\r
376 throw new NotSupportedException ("Callbacks are not supported on CommandField when the select button is enabled because other controls on your page that are dependent on the selected value of '" + Control.ID + "' for their rendering will not update in a callback. Turn callbacks off on '" + Control.ID + "'.");
\r