2010-06-21 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / LinkButton.cs
index 2e581114878d3d36de8bd17fbe9508488504e576..1b5e21bf3119b62e04705f5ad0a99d590e7e204b 100644 (file)
@@ -60,38 +60,41 @@ namespace System.Web.UI.WebControls {
        
                protected override void AddAttributesToRender (HtmlTextWriter w)
                {
-                       if (Page != null)
-                               Page.VerifyRenderingInServerForm (this);
+                       Page page = Page;
+                       if (page != null)
+                               page.VerifyRenderingInServerForm (this);
 
+                       bool enabled = IsEnabled;
 #if NET_2_0
                        string onclick = OnClientClick;
                        onclick = ClientScriptManager.EnsureEndsWithSemicolon (onclick);
-                       if (Attributes ["onclick"] != null) {
+                       if (HasAttributes && Attributes ["onclick"] != null) {
                                onclick = ClientScriptManager.EnsureEndsWithSemicolon (onclick + Attributes ["onclick"]);
                                Attributes.Remove ("onclick");
                        }
 
                        if (onclick.Length > 0)
                                w.AddAttribute (HtmlTextWriterAttribute.Onclick, onclick);
-
-                       if (Enabled && Page != null) {
+                       
+                       if (enabled && page != null) {
                                PostBackOptions options = GetPostBackOptions ();
-                               string href = Page.ClientScript.GetPostBackEventReference (options, true);
+                               string href = page.ClientScript.GetPostBackEventReference (options, true);
                                w.AddAttribute (HtmlTextWriterAttribute.Href, href);
                        }
                        base.AddAttributesToRender (w);
+                       AddDisplayStyleAttribute (w);
 #else
                        base.AddAttributesToRender (w);
-                       if (Page == null || !Enabled)
+                       if (page == null || !enabled)
                                return;
                        
-                       if (CausesValidation && Page.AreValidatorsUplevel ()) {
-                               ClientScriptManager csm = new ClientScriptManager (Page);
+                       if (CausesValidation && page.AreValidatorsUplevel ()) {
+                               ClientScriptManager csm = new ClientScriptManager (page);
                                w.AddAttribute (HtmlTextWriterAttribute.Href,
-                                               String.Format ("javascript:{{if (typeof(Page_ClientValidate) != 'function' ||  Page_ClientValidate()) {0};}}",
-                                                              csm.GetPostBackEventReference (this, String.Empty)));
+                                               String.Concat ("javascript:{if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); ",
+                                                              csm.GetPostBackEventReference (this, String.Empty), ";}"));
                        } else {
-                               w.AddAttribute (HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink (this, ""));
+                               w.AddAttribute (HtmlTextWriterAttribute.Href, page.ClientScript.GetPostBackClientHyperlink (this, String.Empty));
                        }
 #endif
                }
@@ -101,6 +104,9 @@ namespace System.Web.UI.WebControls {
 #endif         
                void RaisePostBackEvent (string eventArgument)
                {
+#if NET_2_0
+                       ValidateEvent (UniqueID, eventArgument);
+#endif
                        if (CausesValidation)
 #if NET_2_0
                                Page.Validate (ValidationGroup);
@@ -142,9 +148,15 @@ namespace System.Web.UI.WebControls {
                protected virtual PostBackOptions GetPostBackOptions ()
                {
                        PostBackOptions options = new PostBackOptions (this);
-                       options.ActionUrl = (PostBackUrl.Length > 0 ? Page.ResolveClientUrl (PostBackUrl) : null);
+                       options.ActionUrl = (PostBackUrl.Length > 0 ?
+#if TARGET_J2EE
+                               CreateActionUrl (PostBackUrl)
+#else
+                               Page.ResolveClientUrl (PostBackUrl) 
+#endif
+                               : null);
                        options.ValidationGroup = null;
-                       options.Argument = "";
+                       options.Argument = String.Empty;
                        options.ClientSubmit = true;
                        options.RequiresJavaScriptProtocol = true;
                        options.PerformValidation = CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup);
@@ -182,7 +194,7 @@ namespace System.Web.UI.WebControls {
 #endif         
                override void RenderContents (HtmlTextWriter writer)
                {
-                       if (HasControls ())
+                       if (HasControls () || HasRenderMethodDelegate ())
                                base.RenderContents (writer);
                        else
                                writer.Write (Text);