2 // System.Web.UI.WebControls.CommandField.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005-2010 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Collections.Specialized;
34 using System.ComponentModel;
35 using System.Security.Permissions;
37 namespace System.Web.UI.WebControls
39 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41 public class CommandField : ButtonFieldBase
43 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
44 [UrlPropertyAttribute]
45 [DefaultValueAttribute ("")]
46 [WebSysDescription ("")]
47 [WebCategoryAttribute ("Appearance")]
48 public virtual string CancelImageUrl {
49 get { return ViewState.GetString ("CancelImageUrl", String.Empty); }
51 ViewState ["CancelImageUrl"] = value;
56 [LocalizableAttribute (true)]
57 [WebSysDescription ("")]
58 [WebCategoryAttribute ("Appearance")]
59 public virtual string CancelText {
60 get { return ViewState.GetString ("CancelText", "Cancel"); }
62 ViewState ["CancelText"] = value;
67 [DefaultValueAttribute (true)]
68 public override bool CausesValidation {
69 get { return ViewState.GetBool ("CausesValidation", true); }
71 ViewState ["CausesValidation"] = value;
76 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
77 [UrlPropertyAttribute]
78 [DefaultValueAttribute ("")]
79 [WebSysDescription ("")]
80 [WebCategoryAttribute ("Appearance")]
81 public virtual string DeleteImageUrl {
82 get { return ViewState.GetString ("DeleteImageUrl", String.Empty); }
84 ViewState ["DeleteImageUrl"] = value;
89 [LocalizableAttribute (true)]
90 [WebSysDescription ("")]
91 [WebCategoryAttribute ("Appearance")]
92 public virtual string DeleteText {
93 get { return ViewState.GetString ("DeleteText", "Delete"); }
95 ViewState ["DeleteText"] = value;
100 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
101 [UrlPropertyAttribute]
102 [DefaultValueAttribute ("")]
103 [WebSysDescription ("")]
104 [WebCategoryAttribute ("Appearance")]
105 public virtual string EditImageUrl {
106 get { return ViewState.GetString ("EditImageUrl", String.Empty); }
108 ViewState ["EditImageUrl"] = value;
113 [LocalizableAttribute (true)]
114 [WebSysDescription ("")]
115 [WebCategoryAttribute ("Appearance")]
116 public virtual string EditText {
117 get { return ViewState.GetString ("EditText", "Edit"); }
119 ViewState ["EditText"] = value;
124 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
125 [UrlPropertyAttribute]
126 [DefaultValueAttribute ("")]
127 [WebSysDescription ("")]
128 [WebCategoryAttribute ("Appearance")]
129 public virtual string InsertImageUrl {
130 get { return ViewState.GetString ("InsertImageUrl", String.Empty); }
132 ViewState ["InsertImageUrl"] = value;
137 [LocalizableAttribute (true)]
138 [WebSysDescription ("")]
139 [WebCategoryAttribute ("Appearance")]
140 public virtual string InsertText {
141 get { return ViewState.GetString ("InsertText", "Insert"); }
143 ViewState ["InsertText"] = value;
148 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
149 [UrlPropertyAttribute]
150 [DefaultValueAttribute ("")]
151 [WebSysDescription ("")]
152 [WebCategoryAttribute ("Appearance")]
153 public virtual string NewImageUrl {
154 get { return ViewState.GetString ("NewImageUrl", String.Empty); }
156 ViewState ["NewImageUrl"] = value;
161 [LocalizableAttribute (true)]
162 [WebSysDescription ("")]
163 [WebCategoryAttribute ("Appearance")]
164 public virtual string NewText {
165 get { return ViewState.GetString ("NewText", "New"); }
167 ViewState ["NewText"] = value;
172 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
173 [UrlPropertyAttribute]
174 [DefaultValueAttribute ("")]
175 [WebSysDescription ("")]
176 [WebCategoryAttribute ("Appearance")]
177 public virtual string SelectImageUrl {
178 get { return ViewState.GetString ("SelectImageUrl", String.Empty); }
180 ViewState ["SelectImageUrl"] = value;
185 [LocalizableAttribute (true)]
186 [WebSysDescription ("")]
187 [WebCategoryAttribute ("Appearance")]
188 public virtual string SelectText {
189 get { return ViewState.GetString ("SelectText", "Select"); }
191 ViewState ["SelectText"] = value;
196 [DefaultValueAttribute (true)]
197 [WebSysDescription ("")]
198 [WebCategoryAttribute ("Behavior")]
199 public virtual bool ShowCancelButton {
200 get { return ViewState.GetBool ("ShowCancelButton", true); }
202 ViewState ["ShowCancelButton"] = value;
207 [DefaultValueAttribute (false)]
208 [WebSysDescription ("")]
209 [WebCategoryAttribute ("Behavior")]
210 public virtual bool ShowDeleteButton {
211 get { return ViewState.GetBool ("ShowDeleteButton", false); }
213 ViewState ["ShowDeleteButton"] = value;
218 [DefaultValueAttribute (false)]
219 [WebSysDescription ("")]
220 [WebCategoryAttribute ("Behavior")]
221 public virtual bool ShowEditButton {
222 get { return ViewState.GetBool ("ShowEditButton", false); }
224 ViewState ["ShowEditButton"] = value;
229 [DefaultValueAttribute (false)]
230 [WebSysDescription ("")]
231 [WebCategoryAttribute ("Behavior")]
232 public virtual bool ShowSelectButton {
233 get { return ViewState.GetBool ("ShowSelectButton", false); }
235 ViewState ["ShowSelectButton"] = value;
240 [DefaultValueAttribute (false)]
241 [WebSysDescription ("")]
242 [WebCategoryAttribute ("Behavior")]
243 public virtual bool ShowInsertButton {
244 get { return ViewState.GetBool ("ShowInsertButton", false); }
246 ViewState ["ShowInsertButton"] = value;
251 [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
252 [UrlPropertyAttribute]
253 [DefaultValueAttribute ("")]
254 [WebSysDescription ("")]
255 [WebCategoryAttribute ("Appearance")]
256 public virtual string UpdateImageUrl {
257 get { return ViewState.GetString ("UpdateImageUrl", String.Empty); }
259 ViewState ["UpdateImageUrl"] = value;
264 [LocalizableAttribute (true)]
265 [WebSysDescription ("")]
266 [WebCategoryAttribute ("Appearance")]
267 public virtual string UpdateText {
268 get { return ViewState.GetString ("UpdateText", "Update"); }
270 ViewState ["UpdateText"] = value;
275 public override void InitializeCell (DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
277 string index = rowIndex.ToString ();
279 if (cellType == DataControlCellType.DataCell) {
280 if ((rowState & DataControlRowState.Edit) != 0) {
281 if (ShowEditButton) {
282 cell.Controls.Add (CreateButton (UpdateText, UpdateImageUrl, DataControlCommands.UpdateCommandName, index));
283 if (ShowCancelButton) {
285 cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
288 } else if ((rowState & DataControlRowState.Insert) != 0) {
289 if (ShowInsertButton) {
290 cell.Controls.Add (CreateButton (InsertText, InsertImageUrl, DataControlCommands.InsertCommandName, index));
291 if (ShowCancelButton) {
293 cell.Controls.Add (CreateButton (CancelText, CancelImageUrl, DataControlCommands.CancelCommandName, index));
297 if (ShowEditButton) {
299 cell.Controls.Add (CreateButton (EditText, EditImageUrl, DataControlCommands.EditCommandName, index));
301 if (ShowDeleteButton) {
303 cell.Controls.Add (CreateButton (DeleteText, DeleteImageUrl, DataControlCommands.DeleteCommandName, index));
305 if (ShowInsertButton) {
307 cell.Controls.Add (CreateButton (NewText, NewImageUrl, DataControlCommands.NewCommandName, index));
309 if (ShowSelectButton) {
311 cell.Controls.Add (CreateButton (SelectText, SelectImageUrl, DataControlCommands.SelectCommandName, index));
315 base.InitializeCell (cell, cellType, rowState, rowIndex);
318 Control CreateButton (string text, string image, string command, string arg)
320 IDataControlButton c = DataControlButton.CreateButton (ButtonType, Control, text, image, command, arg, false);
321 if (CausesValidation) {
322 if (command == DataControlCommands.UpdateCommandName || command == DataControlCommands.InsertCommandName) {
324 c.CausesValidation = true;
325 c.ValidationGroup = ValidationGroup;
331 void AddSeparator (DataControlFieldCell cell)
333 if (cell.Controls.Count > 0) {
334 Literal lit = new Literal ();
336 cell.Controls.Add (lit);
340 protected override DataControlField CreateField ()
342 return new CommandField ();
345 protected override void CopyProperties (DataControlField newField)
347 base.CopyProperties (newField);
348 CommandField field = (CommandField) newField;
349 field.CancelImageUrl = CancelImageUrl;
350 field.CancelText = CancelText;
351 field.DeleteImageUrl = DeleteImageUrl;
352 field.DeleteText = DeleteText;
353 field.EditImageUrl = EditImageUrl;
354 field.EditText = EditText;
355 field.InsertImageUrl = InsertImageUrl;
356 field.InsertText = InsertText;
357 field.NewImageUrl = NewImageUrl;
358 field.NewText = NewText;
359 field.SelectImageUrl = SelectImageUrl;
360 field.SelectText = SelectText;
361 field.ShowCancelButton = ShowCancelButton;
362 field.ShowDeleteButton = ShowDeleteButton;
363 field.ShowEditButton = ShowEditButton;
364 field.ShowSelectButton = ShowSelectButton;
365 field.ShowInsertButton = ShowInsertButton;
366 field.UpdateImageUrl = UpdateImageUrl;
367 field.UpdateText = UpdateText;
370 public override void ValidateSupportsCallback ()
372 if (ShowSelectButton)
373 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 + "'.");