// Authors:
// Jackson Harper (jackson@ximian.com)
//
-// (C) 2005 Novell, Inc.
+// (C) 2005-2010 Novell, Inc.
using System.ComponentModel;
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
// attributes
[DefaultEvent("ServerClick")]
+ [SupportsEventValidation]
public class HtmlButton : HtmlContainerControl, IPostBackEventHandler {
- private static readonly object ServerClickEvent = new object();
+ static readonly object ServerClickEvent = new object();
public HtmlButton () : base ("button")
{
[DefaultValue(true)]
[WebSysDescription("")]
[WebCategory("Behavior")]
-#if NET_2_0
- public virtual
-#else
- public
-#endif
- bool CausesValidation {
+ public virtual bool CausesValidation {
get {
return ViewState.GetBool ("CausesValidation", true);
}
}
}
-#if NET_2_0
[DefaultValue ("")]
- public string ValidationGroup
+ public virtual string ValidationGroup
{
get {
return ViewState.GetString ("ValidationGroup", "");
ViewState ["ValidationGroup"] = value;
}
}
-#endif
-
-#if NET_2_0
void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
{
RaisePostBackEvent (eventArgument);
}
protected virtual void RaisePostBackEvent (string eventArgument)
-#else
- void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
-#endif
{
+ ValidateEvent (UniqueID, eventArgument);
if (CausesValidation)
-#if NET_2_0
Page.Validate (ValidationGroup);
-#else
- Page.Validate ();
-#endif
OnServerClick (EventArgs.Empty);
}
-
-#if NET_2_0
- protected internal
-#else
- protected
-#endif
- override void OnPreRender (EventArgs e)
+
+ protected internal override void OnPreRender (EventArgs e)
{
base.OnPreRender (e);
}
protected override void RenderAttributes (HtmlTextWriter writer)
{
- ClientScriptManager csm = new ClientScriptManager (Page);
- bool postback = false;
-
- if (Page != null && Events [ServerClickEvent] != null)
- postback = true;
-
- if (CausesValidation && Page != null && Page.AreValidatorsUplevel ()) {
- if (postback)
- writer.WriteAttribute ("onclick",
- String.Format ("javascript:{{if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) {0}}}",
- csm.GetPostBackEventReference (this, String.Empty)));
- else
- writer.WriteAttribute ("onclick",
- "if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();");
-
- writer.WriteAttribute ("language", "javascript");
- }
- else if (postback) {
- writer.WriteAttribute ("onclick",
- Page.ClientScript.GetPostBackClientHyperlink (this, ""));
-
+ Page page = Page;
+ if (page != null && Events [ServerClickEvent] != null) {
+ PostBackOptions options = GetPostBackOptions ();
+ Attributes ["onclick"] += page.ClientScript.GetPostBackEventReference (options, true);
writer.WriteAttribute ("language", "javascript");
}
base.RenderAttributes (writer);
}
+ PostBackOptions GetPostBackOptions ()
+ {
+ Page page = Page;
+ PostBackOptions options = new PostBackOptions (this);
+ options.ValidationGroup = null;
+ options.ActionUrl = null;
+ options.Argument = String.Empty;
+ options.RequiresJavaScriptProtocol = false;
+ options.ClientSubmit = true;
+ options.PerformValidation = CausesValidation && page != null && page.AreValidatorsUplevel (ValidationGroup);
+ if (options.PerformValidation)
+ options.ValidationGroup = ValidationGroup;
+
+ return options;
+ }
+
[WebSysDescription("")]
[WebCategory("Action")]
public event EventHandler ServerClick {
remove { Events.RemoveHandler (ServerClickEvent, value); }
}
}
-
}