// 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")]
-#if NET_2_0
[SupportsEventValidation]
-#endif
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 virtual string 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);
-#if NET_2_0
- if (Page != null && Events [ServerClickEvent] != null) {
+ Page page = Page;
+ if (page != null && Events [ServerClickEvent] != null) {
PostBackOptions options = GetPostBackOptions ();
- Attributes ["onclick"] += Page.ClientScript.GetPostBackEventReference (options);
+ Attributes ["onclick"] += page.ClientScript.GetPostBackEventReference (options, true);
writer.WriteAttribute ("language", "javascript");
}
-#else
- 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, ""));
-
- writer.WriteAttribute ("language", "javascript");
- }
-#endif
base.RenderAttributes (writer);
}
-#if NET_2_0
- PostBackOptions GetPostBackOptions () {
+ PostBackOptions GetPostBackOptions ()
+ {
+ Page page = Page;
PostBackOptions options = new PostBackOptions (this);
options.ValidationGroup = null;
options.ActionUrl = null;
- options.Argument = "";
+ options.Argument = String.Empty;
options.RequiresJavaScriptProtocol = false;
options.ClientSubmit = true;
- options.PerformValidation = CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup);
+ options.PerformValidation = CausesValidation && page != null && page.AreValidatorsUplevel (ValidationGroup);
if (options.PerformValidation)
options.ValidationGroup = ValidationGroup;
return options;
}
-#endif
[WebSysDescription("")]
[WebCategory("Action")]
remove { Events.RemoveHandler (ServerClickEvent, value); }
}
}
-
}