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;
37 namespace System.Web.UI.WebControls
39 internal class DataControlButton: Button
43 public DataControlButton (Control container)
45 this.container = container;
48 public DataControlButton (Control container, string text, string image, string command, string commandArg, bool allowCallback)
50 this.container = container;
53 CommandName = command;
54 CommandArgument = commandArg;
55 AllowCallback = allowCallback;
58 public string ImageUrl {
60 object o = ViewState["iu"];
61 if (o != null) return (string) o;
65 ViewState["iu"] = value;
69 public bool AllowCallback {
71 object o = ViewState["ac"];
72 if (o != null) return (bool) o;
76 ViewState["ac"] = value;
80 public virtual ButtonType ButtonType {
82 object ob = ViewState ["ButtonType"];
83 if (ob != null) return (ButtonType) ob;
84 return ButtonType.Link;
87 ViewState ["ButtonType"] = value;
91 protected internal override void Render (HtmlTextWriter writer)
93 if (CommandName.Length > 0 || ButtonType == ButtonType.Button)
95 string postScript = null;
96 string callScript = null;
98 IPostBackContainer pcner = container as IPostBackContainer;
100 PostBackOptions ops = pcner.GetPostBackOptions (this);
101 postScript = container.Page.ClientScript.GetPostBackEventReference (ops);
103 postScript = Page.ClientScript.GetPostBackEventReference (this, "");
105 if (CausesValidation && Page.Validators.Count > 0) {
106 // TOSHOK: review if this is the correct usage of the "fresh" client side stuff
107 ClientScriptManager csm = new ClientScriptManager (Page);
108 postScript = csm.GetClientValidationEvent () + postScript;
112 ICallbackContainer ccner = container as ICallbackContainer;
114 callScript = ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
117 ControlStyle.AddAttributesToRender (writer);
119 if (ButtonType == ButtonType.Image) {
120 writer.AddAttribute (HtmlTextWriterAttribute.Type, "image");
121 writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveClientUrl (ImageUrl));
122 if (callScript != null)
123 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
125 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, postScript);
127 writer.AddAttribute (HtmlTextWriterAttribute.Alt, Text);
128 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, "0px");
129 writer.RenderBeginTag (HtmlTextWriterTag.Input);
130 writer.RenderEndTag ();
132 if (ButtonType == ButtonType.Link) {
133 if (callScript != null) {
134 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
135 writer.AddAttribute (HtmlTextWriterAttribute.Href, "javascript:");
138 writer.AddAttribute (HtmlTextWriterAttribute.Href, "javascript:" + postScript);
139 writer.RenderBeginTag (HtmlTextWriterTag.A);
141 writer.RenderEndTag ();
143 if (ButtonType == ButtonType.Button) {
144 if (callScript != null)
145 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
147 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, postScript);
149 writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
150 writer.AddAttribute (HtmlTextWriterAttribute.Name, ClientID);
151 writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
152 writer.RenderBeginTag (HtmlTextWriterTag.Input);
153 writer.RenderEndTag ();
157 if (ImageUrl.Length > 0) {
158 ControlStyle.AddAttributesToRender (writer);
159 writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveClientUrl (ImageUrl));
161 writer.AddAttribute (HtmlTextWriterAttribute.Alt, Text);
162 writer.AddStyleAttribute (HtmlTextWriterStyle.BorderWidth, "0px");
163 writer.RenderBeginTag (HtmlTextWriterTag.Img);
164 writer.RenderEndTag ();
167 if (!ControlStyle.IsEmpty) {
168 ControlStyle.AddAttributesToRender (writer);
170 writer.RenderBeginTag (HtmlTextWriterTag.Span);
172 writer.RenderEndTag ();