2 // Permission is hereby granted, free of charge, to any person obtaining
3 // a copy of this software and associated documentation files (the
4 // "Software"), to deal in the Software without restriction, including
5 // without limitation the rights to use, copy, modify, merge, publish,
6 // distribute, sublicense, and/or sell copies of the Software, and to
7 // permit persons to whom the Software is furnished to do so, subject to
8 // the following conditions:
10 // The above copyright notice and this permission notice shall be
11 // included in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // System.Web.UI.HtmlControls.HtmlButton
25 // Jackson Harper (jackson@ximian.com)
27 // (C) 2005-2010 Novell, Inc.
30 using System.ComponentModel;
31 using System.Security.Permissions;
33 namespace System.Web.UI.HtmlControls {
36 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 [DefaultEvent("ServerClick")]
40 [SupportsEventValidation]
41 public class HtmlButton : HtmlContainerControl, IPostBackEventHandler {
43 static readonly object ServerClickEvent = new object();
45 public HtmlButton () : base ("button")
50 [WebSysDescription("")]
51 [WebCategory("Behavior")]
52 public virtual bool CausesValidation {
54 return ViewState.GetBool ("CausesValidation", true);
57 ViewState ["CausesValidation"] = value;
62 public virtual string ValidationGroup
65 return ViewState.GetString ("ValidationGroup", "");
68 ViewState ["ValidationGroup"] = value;
71 void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
73 RaisePostBackEvent (eventArgument);
76 protected virtual void RaisePostBackEvent (string eventArgument)
78 ValidateEvent (UniqueID, eventArgument);
80 Page.Validate (ValidationGroup);
81 OnServerClick (EventArgs.Empty);
84 protected internal override void OnPreRender (EventArgs e)
89 protected virtual void OnServerClick (EventArgs e)
91 EventHandler server_click = (EventHandler) Events [ServerClickEvent];
92 if (server_click != null)
93 server_click (this, e);
96 protected override void RenderAttributes (HtmlTextWriter writer)
99 if (page != null && Events [ServerClickEvent] != null) {
100 PostBackOptions options = GetPostBackOptions ();
101 Attributes ["onclick"] += page.ClientScript.GetPostBackEventReference (options, true);
102 writer.WriteAttribute ("language", "javascript");
105 base.RenderAttributes (writer);
108 PostBackOptions GetPostBackOptions ()
111 PostBackOptions options = new PostBackOptions (this);
112 options.ValidationGroup = null;
113 options.ActionUrl = null;
114 options.Argument = String.Empty;
115 options.RequiresJavaScriptProtocol = false;
116 options.ClientSubmit = true;
117 options.PerformValidation = CausesValidation && page != null && page.AreValidatorsUplevel (ValidationGroup);
118 if (options.PerformValidation)
119 options.ValidationGroup = ValidationGroup;
124 [WebSysDescription("")]
125 [WebCategory("Action")]
126 public event EventHandler ServerClick {
127 add { Events.AddHandler (ServerClickEvent, value); }
128 remove { Events.RemoveHandler (ServerClickEvent, value); }