2 // System.Web.UI.WebControls.DataControlButton.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005-2010 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.ComponentModel;
32 using System.ComponentModel.Design;
35 namespace System.Web.UI.WebControls
37 internal interface IDataControlButton : IButtonControl
39 Control Container { get; set;}
40 string ImageUrl { get;set;}
41 bool AllowCallback { get; set;}
42 ButtonType ButtonType { get;}
45 [SupportsEventValidation]
46 internal class DataControlButton : Button, IDataControlButton
48 public static IDataControlButton CreateButton (ButtonType type, Control container, string text, string image, string command, string commandArg, bool allowCallback)
50 IDataControlButton btn;
54 btn = new DataControlLinkButton ();
56 case ButtonType.Image:
57 btn = new DataControlImageButton ();
61 btn = new DataControlButton ();
65 btn.Container = container;
66 btn.CommandName = command;
67 btn.CommandArgument = commandArg;
69 btn.CausesValidation = false;
70 btn.AllowCallback = allowCallback;
77 public Control Container {
78 get { return _container; }
79 set { _container = value; }
82 public string ImageUrl {
83 get { return String.Empty; }
87 public bool AllowCallback {
88 get { return ViewState.GetBool ("AllowCallback", true); }
89 set { ViewState ["AllowCallback"] = value; }
92 public ButtonType ButtonType {
93 get { return ButtonType.Button; }
96 public override bool UseSubmitBehavior {
98 set { throw new NotSupportedException (); }
101 internal override string GetClientScriptEventReference ()
104 ICallbackContainer ccner = Container as ICallbackContainer;
106 return ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
108 return base.GetClientScriptEventReference ();
111 protected override PostBackOptions GetPostBackOptions ()
113 IPostBackContainer pcner = Container as IPostBackContainer;
115 return pcner.GetPostBackOptions (this);
116 return base.GetPostBackOptions ();
120 internal class DataControlLinkButton : LinkButton, IDataControlButton
124 public Control Container {
125 get { return _container; }
126 set { _container = value; }
129 public string ImageUrl {
130 get { return String.Empty; }
134 public bool AllowCallback {
135 get { return ViewState.GetBool ("AllowCallback", true); }
136 set { ViewState ["AllowCallback"] = value; }
139 public ButtonType ButtonType {
140 get { return ButtonType.Link; }
143 protected internal override void Render (HtmlTextWriter writer)
147 ICallbackContainer ccner = Container as ICallbackContainer;
149 OnClientClick = ClientScriptManager.EnsureEndsWithSemicolon (OnClientClick) + ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
152 base.Render (writer);
155 void EnsureForeColor ()
157 if (ForeColor != Color.Empty)
160 for (Control parent = Parent; parent != null; parent = parent.Parent) {
161 WebControl wc = parent as WebControl;
162 if (wc != null && wc.ForeColor != Color.Empty) {
163 ForeColor = wc.ForeColor;
166 if (parent == Container)
171 protected override PostBackOptions GetPostBackOptions ()
173 IPostBackContainer pcner = Container as IPostBackContainer;
175 return pcner.GetPostBackOptions (this);
176 return base.GetPostBackOptions ();
181 internal class DataControlImageButton : ImageButton, IDataControlButton
185 public Control Container {
186 get { return _container; }
187 set { _container = value; }
190 public bool AllowCallback {
191 get { return ViewState.GetBool ("AllowCallback", true); }
192 set { ViewState ["AllowCallback"] = value; }
195 public ButtonType ButtonType {
196 get { return ButtonType.Image; }
199 internal override string GetClientScriptEventReference ()
202 ICallbackContainer ccner = Container as ICallbackContainer;
204 return ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
206 return base.GetClientScriptEventReference ();
209 protected override PostBackOptions GetPostBackOptions ()
211 IPostBackContainer pcner = Container as IPostBackContainer;
213 return pcner.GetPostBackOptions (this);
214 return base.GetPostBackOptions ();