Beispiel #1
0
        private void AddDiagnosticMetadataAttributes(HtmlTextWriter writer)
        {
            IControlWithDiagnosticMetadata controlWithDiagnosticMetadata = this;

            writer.AddAttribute(DiagnosticMetadataAttributes.ControlType, controlWithDiagnosticMetadata.ControlType);

            if (!string.IsNullOrEmpty(Text))
            {
                writer.AddAttribute(DiagnosticMetadataAttributes.Content, HtmlUtility.StripHtmlTags(Text));
            }

            if (!string.IsNullOrEmpty(CommandName))
            {
                writer.AddAttribute(DiagnosticMetadataAttributes.CommandName, CommandName);
            }

            if (!string.IsNullOrEmpty(ID))
            {
                writer.AddAttribute(DiagnosticMetadataAttributes.ItemID, ID);
            }

            var triggersPostBack = !OnClientClick.Contains(";return ");

            writer.AddAttribute(DiagnosticMetadataAttributes.TriggersPostBack, triggersPostBack.ToString().ToLower());
        }
Beispiel #2
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
        }
Beispiel #3
0
        /// <summary>
        /// <inheritdoc />
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="cssClasses"></param>
        protected override void AddAttributesToRender(IDictionary <HtmlTextWriterAttribute, string> attributes, ICollection <string> cssClasses)
        {
            if (this.IsDefault)
            {
                cssClasses.Add("ui-priority-primary");
            }

            if (!IsScriptNeeded())
            {
                if (this.CssClasses.Length == 0)
                {
                    cssClasses.Add("ui-state-default");
                }
                cssClasses.Add("ui-button");
                cssClasses.Add("ui-widget");
                cssClasses.Add("ui-corner-all");
                if (this.Icon != ButtonIconType.None)
                {
                    if (string.IsNullOrEmpty(this.Text))
                    {
                        cssClasses.Add("ui-button-icon-only");
                    }
                    else
                    {
                        cssClasses.Add("ui-button-text-icon-primary");
                    }
                }
                else
                {
                    cssClasses.Add("ui-button-text-only");
                }
            }

            switch (this.Action)
            {
            case ButtonAction.Submit:
                // Button
                attributes.Add(HtmlTextWriterAttribute.Type, "submit");
                if (!string.IsNullOrEmpty(this.UniqueID))
                {
                    // UniqueID can be null when buton is not part of a page
                    attributes.Add(HtmlTextWriterAttribute.Name, this.UniqueID);
                }
                break;

            case ButtonAction.Reset:
                // A
                attributes.Add(HtmlTextWriterAttribute.Href, this.Page.Request.RawUrl);
                break;


            case ButtonAction.Navigate:
                // A. OnClientClick interpreted as URL
                attributes.Add(HtmlTextWriterAttribute.Href, this.ResolveUrl(this.OnClientClick));
                break;

            case ButtonAction.NewWindow:
                // A
                attributes.Add(HtmlTextWriterAttribute.Href, this.ResolveUrl(this.OnClientClick));

                // Each distinct URL will open in a different window. Same URL will reuse the previously opened window.
                attributes.Add(HtmlTextWriterAttribute.Target, OnClientClick.GetHashCode().ToString());
                break;

            case ButtonAction.None:
                // Button
                attributes.Add(HtmlTextWriterAttribute.Type, "button");
                break;

            default:
                throw new NotImplementedException();
            }


            if (!string.IsNullOrEmpty(this.ToolTip))
            {
                attributes.Add(HtmlTextWriterAttribute.Title, this.ToolTip);
            }
            if (!string.IsNullOrEmpty(this.AccessKey))
            {
                attributes.Add(HtmlTextWriterAttribute.Accesskey, this.AccessKey);
            }
            if (this.TabIndex != 0)
            {
                attributes.Add(HtmlTextWriterAttribute.Tabindex, this.TabIndex.ToString());
            }
            base.AddAttributesToRender(attributes, cssClasses);
        }
Beispiel #4
0
        public override void RenderControl(HtmlTextWriter writer)
        {
            if (Visible)
            {
                if (this.Page != null)
                {
                    this.Page.VerifyRenderingInServerForm(this);
                }

                //输入框
                writer.AddAttribute(HtmlTextWriterAttribute.Id, base.ClientID);
                writer.AddAttribute(HtmlTextWriterAttribute.Name, base.UniqueID);
                writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "true");
                writer.AddAttribute(HtmlTextWriterAttribute.Type, "Text");
                writer.AddAttribute(HtmlTextWriterAttribute.Value, this._seletedDate == DateTime.MinValue ? "" : this._seletedDate.ToString("yyyy/MM/dd"));
                if (!this.Disabled)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Onclick, OnClientClick.Replace("#ClientID#", "this").Replace("#ImageClientID#", "document.getElementById('" + base.ClientID + "_Picker')"), false);
                    //string strclick = OnClientClick.Replace("#ClientID#", "this").Replace("#ImageClientID#", "document.getElementById('" + base.ClientID + "_Picker')");

                    if (!DesignMode)
                    {
                        string str4 = "";
                        if (base.HasAttributes)
                        {
                            str4 = base.Attributes["onchange"];
                            if (str4 != null)
                            {
                                str4 = ComFunc.EnsureEndWithSemiColon(str4);
                                base.Attributes.Remove("onchange");
                            }
                        }

                        EventHandler handler = (EventHandler)base.Events[EventTextChanged];
                        if (handler != null)
                        {
                            PostBackOptions options = new PostBackOptions(this, string.Empty);
                            if (this.CausesValidation)
                            {
                                options.PerformValidation = true;
                                options.ValidationGroup   = this.ValidationGroup;
                            }
                            if (Page.Form != null)
                            {
                                options.AutoPostBack = true;
                            }
                            str4 = ComFunc.MergeScript(str4, Page.ClientScript.GetPostBackEventReference(options, true));
                            writer.AddAttribute("onpropertychange", str4);
                        }
                    }
                }
                writer.AddStyleAttribute(HtmlTextWriterStyle.Width, this.TextWidth.ToString() + "px");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Height, this.TextHeight.ToString() + "px");

                writer.RenderBeginTag(HtmlTextWriterTag.Input);
                writer.RenderEndTag();
                //添加空格
                writer.Write("&nbsp;");
                //image
                writer.AddAttribute(HtmlTextWriterAttribute.Id, base.ClientID + "_Picker");
                writer.AddAttribute(HtmlTextWriterAttribute.Name, base.UniqueID + "$Picker");
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, OnClientClick.Replace("#ClientID#", "document.getElementById('" + base.ClientID + "')").Replace("#ImageClientID#", "document.getElementById('" + base.ClientID + "_Picker')"));

                if (DesignMode)
                {
                    //string directoryPath = ComFunc.GetProjectPathInDesignMode();
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveClientUrl(this.ImgPath));
                }
                else
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveClientUrl(this.ImgPath));
                }

                if (this.Disabled)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "true");
                }

                writer.AddStyleAttribute(HtmlTextWriterStyle.Width, this.ImgWidth.ToString() + "px");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Height, this.ImgHeight.ToString() + "px");

                writer.RenderBeginTag(HtmlTextWriterTag.Img);
                writer.RenderEndTag();
            }
        }