Пример #1
0
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            if (string.IsNullOrEmpty(AccessKey) && _textWithHotkey.Hotkey.HasValue)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, HotkeyFormatter.FormatHotkey(_textWithHotkey));
            }

            base.AddAttributesToRender(writer);
        }
        protected override Command RenderBeginTagForCommand(WebTabStripRenderingContext renderingContext, IWebTab tab, bool isEnabled, WebTabStyle style)
        {
            ArgumentUtility.CheckNotNull("style", style);

            var menuTab = ((IMenuTab)tab).GetActiveTab();
            var command = GetRenderingCommand(isEnabled, menuTab);

            var additionalUrlParameters = menuTab.GetUrlParameters();
            var backupID        = command.ItemID;
            var backupAccessKey = command.AccessKey;

            try
            {
                if (string.IsNullOrEmpty(command.ItemID) && !string.IsNullOrEmpty(tab.ItemID))
                {
                    command.ItemID = tab.ItemID + "_Command";
                }

                if (string.IsNullOrEmpty(command.AccessKey))
                {
                    var textWithHotkey = HotkeyParser.Parse(tab.Text);
                    if (textWithHotkey.Hotkey.HasValue)
                    {
                        command.AccessKey = HotkeyFormatter.FormatHotkey(textWithHotkey);
                    }
                }

                command.RenderBegin(
                    renderingContext.Writer,
                    RenderingFeatures,
                    tab.GetPostBackClientEvent(),
                    new string[0],
                    string.Empty,
                    null,
                    additionalUrlParameters,
                    false,
                    style);

                return(command);
            }
            finally
            {
                command.ItemID    = backupID;
                command.AccessKey = backupAccessKey;
            }
        }
Пример #3
0
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            if (string.IsNullOrEmpty(AccessKey) && _textWithHotkey.Hotkey.HasValue)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, HotkeyFormatter.FormatHotkey(_textWithHotkey));
            }

            if (IsLegacyButtonEnabled)
            {
                if (!string.IsNullOrEmpty(_textWithHotkey.Text))
                {
                    Text = _textWithHotkey.Text;
                }
                else if (_icon != null && _icon.HasRenderingInformation)
                {
                    Text = _icon.AlternateText;
                }
            }

            if (Page != null)
            {
                Page.VerifyRenderingInServerForm(this);
            }

            if (IsEnabled)
            {
                string onClick = EnsureEndWithSemiColon(OnClientClick);
                if (HasAttributes)
                {
                    string onClickAttribute = Attributes["onclick"];
                    if (onClickAttribute != null)
                    {
                        onClick += EnsureEndWithSemiColon(onClickAttribute);
                        Attributes.Remove("onclick");
                    }
                }

                if (Page != null)
                {
                    var options = GetPostBackOptions();
                    options.ClientSubmit = true;

                    var postBackEventReference = Page.ClientScript.GetPostBackEventReference(options, false);
                    if (string.IsNullOrEmpty(postBackEventReference))
                    {
                        postBackEventReference = Page.ClientScript.GetPostBackEventReference(this, null);
                    }
                    var postBackScript = EnsureEndWithSemiColon(postBackEventReference);

                    onClick += postBackScript;
                    onClick += "return false;";
                }

                if (!string.IsNullOrEmpty(onClick))
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick);
                }

                writer.AddAttribute("onmousedown", "WebButton_MouseDown (this, '" + CssClassMouseDown + "');");
                writer.AddAttribute("onmouseup", "WebButton_MouseUp (this, '" + CssClassMouseDown + "');");
                writer.AddAttribute("onmouseout", "WebButton_MouseOut (this, '" + CssClassMouseDown + "');");
            }


            _options = base.GetPostBackOptions();
            _options.ClientSubmit      = false;
            _options.PerformValidation = false;
            _options.AutoPostBack      = false;

            string backUpOnClientClick = OnClientClick;

            OnClientClick = null;

            var cssClassBackup       = ControlStyle.CssClass;
            var originalCssClass     = (CssClass ?? "").Replace(DisabledCssClass, "").Trim();
            var isCssStyleOverridden = !string.IsNullOrEmpty(originalCssClass);
            var computedCssClass     = isCssStyleOverridden ? originalCssClass : CssClassBase;

            ControlStyle.CssClass = computedCssClass;

            base.AddAttributesToRender(writer);

            ControlStyle.CssClass = cssClassBackup;

            OnClientClick = backUpOnClientClick;

            // Must be after OnClientClick has been reset
            if (_renderingFeatures.EnableDiagnosticMetadata)
            {
                AddDiagnosticMetadataAttributes(writer);
            }

            _options = null;
        }