Exemple #1
0
        protected override void Render(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Class, "btn-c" + (CssSpan.IsNotEmpty() ? " " + CssSpan : ""));
            writer.RenderBeginTag(HtmlTextWriterTag.Span);

            if (Href.IsNotEmpty() && Click != null)
            {
                throw new Exception("Href and Server Event can't be used together");
            }

            if (Click != null)
            {
                //Uncomment if POSTBACK is not rising
                //writer.AddAttribute(HtmlTextWriterAttribute.Name, ClientID);
                if (DisableValidation)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:" + Page.ClientScript.GetPostBackEventReference(this, ClientID));
                }
                else
                {
                    //Uncomment if POSTBACK is not rising
                    //writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:" + string.Format("__doPostBackJQ('{0}','{1}')", UniqueID, ClientID));
                    writer.AddAttribute(HtmlTextWriterAttribute.Href, "javascript:" + string.Format("__doPostBackJQ('{0}','')", UniqueID));
                }

                writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
            }
            else
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Href, Href.IsNotEmpty() ? Href : "javascript:void(0);");
            }

            if (OnClientClick.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, OnClientClick);
            }

            if (Rel.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Rel, Rel);
            }

            if (Target.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Target, Target);
            }

            if (CssStyle.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Style, CssStyle);
            }

            writer.AddAttribute(HtmlTextWriterAttribute.Class, string.Format("btn{0}{1}{2}{3}",
                                                                             Type != eType.None ? " btn-" + Type.ToString().ToLower() : string.Empty,
                                                                             Size != eSize.None ? " btn-" + Size.ToString().ToLower() : string.Empty,
                                                                             CssClass.IsNotEmpty() ? " " + CssClass : string.Empty,
                                                                             ValidationGroup.IsNotEmpty() ? " group-" + ValidationGroup : string.Empty));
            if (ID.IsNotEmpty())
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Id, ID);
            }

            IEnumerator keys = this.Attributes.Keys.GetEnumerator();

            while (keys.MoveNext())
            {
                var key = (String)keys.Current;
                writer.AddAttribute(key, this.Attributes[key]);
            }

            writer.RenderBeginTag(HtmlTextWriterTag.A);
            writer.Write(Text);
            writer.RenderEndTag(); // a

            writer.RenderEndTag(); // span
        }