Ejemplo n.º 1
0
        /// <summary>
        /// Overrides <see cref="WebControl.AddAttributesToRender"/>
        /// </summary>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Type, "button");
            writer.AddAttribute("value", this.Text);
            writer.AddAttribute("language", "javascript");

            String myOnclick = " return false; ";

            // prepend the dialog open script to the onclick script
            if (System.Web.HttpContext.Current != null && this.Page != null && this.Enabled && this.DialogToOpen != null && this.DialogToOpen.Length != 0)
            {
                DialogWindowBase dialog = this.NamingContainer.FindControl(this.DialogToOpen) as DialogWindowBase;
                if (dialog == null)
                {
                    dialog = this.Page.FindControl(this.DialogToOpen) as DialogWindowBase;
                }
                if (dialog == null)
                {
                    throw new InvalidOperationException("Cannot find a DialogWindow with the name '" + this.DialogToOpen + "'");
                }

                myOnclick = dialog.GetDialogOpenScript() + "; " + myOnclick;
            }

            // prepend the user's onclick script to mine
            if (this.Attributes["onclick"] != null)
            {
                myOnclick = this.Attributes["onclick"] + myOnclick;
                this.Attributes.Remove("onclick");
            }

            // write the final onclick
            writer.AddAttribute("onclick", myOnclick);

            base.AddAttributesToRender(writer);
        }