2 // System.Web.UI.WebControls.DataControlButton.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
7 // (C) 2005 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.
34 using System.ComponentModel;
35 using System.ComponentModel.Design;
38 namespace System.Web.UI.WebControls
40 internal interface IDataControlButton : IButtonControl
42 Control Container { get; set;}
43 string ImageUrl { get;set;}
44 bool AllowCallback { get; set;}
45 ButtonType ButtonType { get;}
48 internal class DataControlButton : Button, IDataControlButton
50 public static IDataControlButton CreateButton (ButtonType type, Control container, string text, string image, string command, string commandArg, bool allowCallback)
52 IDataControlButton btn;
56 btn = new DataControlLinkButton ();
58 case ButtonType.Image:
59 btn = new DataControlImageButton ();
63 btn = new DataControlButton ();
67 btn.Container = container;
68 btn.CommandName = command;
69 btn.CommandArgument = commandArg;
71 btn.CausesValidation = false;
72 btn.AllowCallback = allowCallback;
79 public Control Container {
80 get { return _container; }
81 set { _container = value; }
84 public string ImageUrl {
85 get { return String.Empty; }
89 public bool AllowCallback {
90 get { return ViewState.GetBool ("AllowCallback", true); }
91 set { ViewState ["AllowCallback"] = value; }
94 public ButtonType ButtonType {
95 get { return ButtonType.Button; }
98 public override bool UseSubmitBehavior {
100 set { throw new NotSupportedException (); }
103 internal override string GetClientScriptEventReference ()
106 ICallbackContainer ccner = Container as ICallbackContainer;
108 return ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
110 return base.GetClientScriptEventReference ();
113 protected override PostBackOptions GetPostBackOptions ()
115 IPostBackContainer pcner = Container as IPostBackContainer;
117 return pcner.GetPostBackOptions (this);
118 return base.GetPostBackOptions ();
122 internal class DataControlLinkButton : LinkButton, IDataControlButton
126 public Control Container {
127 get { return _container; }
128 set { _container = value; }
131 public string ImageUrl {
132 get { return String.Empty; }
136 public bool AllowCallback {
137 get { return ViewState.GetBool ("AllowCallback", true); }
138 set { ViewState ["AllowCallback"] = value; }
141 public ButtonType ButtonType {
142 get { return ButtonType.Link; }
145 protected internal override void Render (HtmlTextWriter writer)
149 ICallbackContainer ccner = Container as ICallbackContainer;
151 OnClientClick = ClientScriptManager.EnsureEndsWithSemicolon (OnClientClick) + ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
154 base.Render (writer);
157 void EnsureForeColor ()
159 if (ForeColor != Color.Empty)
162 for (Control parent = Parent; parent != null; parent = parent.Parent) {
163 WebControl wc = parent as WebControl;
164 if (wc != null && wc.ForeColor != Color.Empty) {
165 ForeColor = wc.ForeColor;
168 if (parent == Container)
173 protected override PostBackOptions GetPostBackOptions ()
175 IPostBackContainer pcner = Container as IPostBackContainer;
177 return pcner.GetPostBackOptions (this);
178 return base.GetPostBackOptions ();
183 internal class DataControlImageButton : ImageButton, IDataControlButton
187 public Control Container {
188 get { return _container; }
189 set { _container = value; }
192 public bool AllowCallback {
193 get { return ViewState.GetBool ("AllowCallback", true); }
194 set { ViewState ["AllowCallback"] = value; }
197 public ButtonType ButtonType {
198 get { return ButtonType.Image; }
201 internal override string GetClientScriptEventReference ()
204 ICallbackContainer ccner = Container as ICallbackContainer;
206 return ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
208 return base.GetClientScriptEventReference ();
211 protected override PostBackOptions GetPostBackOptions ()
213 IPostBackContainer pcner = Container as IPostBackContainer;
215 return pcner.GetPostBackOptions (this);
216 return base.GetPostBackOptions ();