2 // System.Web.UI.WebControls.DataControlButton.cs
\r
5 // Lluis Sanchez Gual (lluis@novell.com)
\r
7 // (C) 2005 Novell, Inc (http://www.novell.com)
\r
9 // Permission is hereby granted, free of charge, to any person obtaining
\r
10 // a copy of this software and associated documentation files (the
\r
11 // "Software"), to deal in the Software without restriction, including
\r
12 // without limitation the rights to use, copy, modify, merge, publish,
\r
13 // distribute, sublicense, and/or sell copies of the Software, and to
\r
14 // permit persons to whom the Software is furnished to do so, subject to
\r
15 // the following conditions:
\r
17 // The above copyright notice and this permission notice shall be
\r
18 // included in all copies or substantial portions of the Software.
\r
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
33 using System.Web.UI;
\r
34 using System.ComponentModel;
35 using System.ComponentModel.Design;
\r
37 namespace System.Web.UI.WebControls
\r
39 internal class DataControlButton: Button
\r
43 public DataControlButton (Control container)
\r
45 this.container = container;
\r
48 public DataControlButton (Control container, string text, string image, string command, string commandArg, bool allowCallback)
\r
50 this.container = container;
\r
53 CommandName = command;
\r
54 CommandArgument = commandArg;
\r
55 AllowCallback = allowCallback;
\r
58 public string ImageUrl {
\r
60 object o = ViewState["iu"];
\r
61 if (o != null) return (string) o;
\r
62 return String.Empty;
\r
65 ViewState["iu"] = value;
\r
69 public bool AllowCallback {
\r
71 object o = ViewState["ac"];
\r
72 if (o != null) return (bool) o;
\r
76 ViewState["ac"] = value;
\r
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 override void Render (HtmlTextWriter writer)
\r
93 if (CommandName.Length > 0 || ButtonType == ButtonType.Button)
\r
95 string postScript = null;
\r
96 string callScript = null;
\r
98 IPostBackContainer pcner = container as IPostBackContainer;
99 if (pcner != null) {
\r
100 PostBackOptions ops = pcner.GetPostBackOptions (this);
\r
101 postScript = container.Page.ClientScript.GetPostBackEventReference (ops);
\r
103 postScript = Page.ClientScript.GetPostBackClientEvent (this, "");
\r
105 if (CausesValidation && Page.Validators.Count > 0) {
\r
106 postScript = Utils.GetClientValidatedEvent (Page) + postScript;
\r
109 if (AllowCallback) {
\r
110 ICallbackContainer ccner = container as ICallbackContainer;
\r
112 callScript = ccner.GetCallbackScript (this, CommandName + "$" + CommandArgument);
\r
115 if (ButtonType == ButtonType.Link || ButtonType == ButtonType.Image)
117 if (ImageUrl.Length > 0) {
\r
118 writer.AddAttribute (HtmlTextWriterAttribute.Type, "image");
\r
119 writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (ImageUrl));
\r
120 if (callScript != null)
\r
121 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
\r
123 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, postScript);
\r
124 if (Text.Length > 0)
\r
125 writer.AddAttribute (HtmlTextWriterAttribute.Alt, Text);
\r
126 writer.RenderBeginTag (HtmlTextWriterTag.Input);
\r
127 writer.RenderEndTag ();
\r
130 if (callScript != null) {
\r
131 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
\r
132 writer.AddAttribute (HtmlTextWriterAttribute.Href, "javascript:");
\r
135 writer.AddAttribute (HtmlTextWriterAttribute.Href, postScript);
\r
136 writer.RenderBeginTag (HtmlTextWriterTag.A);
\r
137 writer.Write (Text);
\r
138 writer.RenderEndTag ();
\r
141 else if (ButtonType == ButtonType.Button)
143 if (callScript != null)
\r
144 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, callScript);
\r
146 writer.AddAttribute (HtmlTextWriterAttribute.Onclick, postScript);
148 writer.AddAttribute (HtmlTextWriterAttribute.Type, "submit");
\r
149 writer.AddAttribute (HtmlTextWriterAttribute.Name, ClientID);
\r
150 writer.AddAttribute (HtmlTextWriterAttribute.Value, Text);
\r
151 writer.RenderBeginTag (HtmlTextWriterTag.Input);
\r
152 writer.RenderEndTag ();
\r
155 if (ImageUrl.Length > 0) {
\r
156 writer.AddAttribute (HtmlTextWriterAttribute.Src, ResolveUrl (ImageUrl));
\r
157 if (Text.Length > 0)
\r
158 writer.AddAttribute (HtmlTextWriterAttribute.Alt, Text);
\r
159 writer.RenderBeginTag (HtmlTextWriterTag.Img);
\r
160 writer.RenderEndTag ();
\r
163 writer.Write (Text);
\r