コード例 #1
0
        /// <summary>
        /// Gets the on click button HTML.
        /// </summary>
        /// <param name="handlerCode">The hander code.</param>
        /// <param name="imageUrl">The image URL.</param>
        /// <param name="text">The button text.</param>
        /// <param name="alternateText">Alternate image text</param>
        /// <returns></returns>
        public string GetOnClickButtonHtml(string handlerCode, string imageUrl, string text, string alternateText)
        {
            DynamicGridButton button = new DynamicGridButton();

            if (!string.IsNullOrEmpty(imageUrl))
            {
                button.ImageUrl = ControlHelper.GetFullImageUrl(imageUrl, Page);
            }

            button.OnClientClick = handlerCode;
            button.Text          = text;
            button.AlternateText = alternateText;
            return(button.GetHTML());
        }
コード例 #2
0
        private void AddAttributesToRenderForTypeImageButton(HtmlTextWriter writer)
        {
            Page page = Page;

            writer.AddAttribute(HtmlTextWriterAttribute.Type, "image");

            string          text1           = UniqueID;
            PostBackOptions postBackOptions = GetPostBackOptionsForTypeImageButton();

            if ((text1 != null) && ((postBackOptions == null) || (postBackOptions.TargetControl == this)))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Name, text1);
            }
            bool   isEnabled           = IsEnabled;
            string onClientClickScript = string.Empty;

            if (isEnabled)
            {
                onClientClickScript = Util.EnsureEndWithSemiColon(OnClientClick);
                if (HasAttributes)
                {
                    string text3 = Attributes["onclick"];
                    if (text3 != null)
                    {
                        onClientClickScript = onClientClickScript + Util.EnsureEndWithSemiColon(text3);
                        Attributes.Remove("onclick");
                    }
                }
            }
            if (Enabled && !isEnabled)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
            }
            base.AddAttributesToRender(writer);
            if ((page != null) && (postBackOptions != null))
            {
                page.ClientScript.RegisterForEventValidation(postBackOptions);
                if (isEnabled)
                {
                    string text4 = page.ClientScript.GetPostBackEventReference(postBackOptions, false);
                    if (!string.IsNullOrEmpty(text4))
                    {
                        onClientClickScript = Util.MergeScript(onClientClickScript, text4);
                    }
                }
            }
            if (onClientClickScript.Length > 0)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Onclick, onClientClickScript);
                //if (base.EnableLegacyRendering)
                //{
                //    writer.AddAttribute("language", "javascript", false);
                //}
            }
            if (page != null)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Src,
                                    ControlHelper.GetFullImageUrl(ImageUrl, page));
            }
            else
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Src, ImageUrl);
            }
        }