AjaxToolkit:页面最后一个 TabContainer 专注于页面加载 [英] AjaxToolkit: the last TabContainer on the page is focused on page load

查看:15
本文介绍了AjaxToolkit:页面最后一个 TabContainer 专注于页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 ASP.NET 项目的页面上使用了多个 TabContainer,我注意到一个非常奇怪的行为:当页面加载时,焦点跳转到页面上的最后一个 TabContainer,导致它向下滚动.我没有明确关注任何控制,所以我不明白这是从哪里来的.我还在控件之间切换了位置,并且始终是最后一个焦点.TabContainers 没有任何花哨的设置,这基本上就是它们的样子:

I'm using more than one TabContainer on a page in an ASP.NET project and I noticed a really strange behavior: when the page is loaded the focus jumps to the last TabContainer on the page, causing it to scroll down. I don't explicitly focus on any control so I don't understand where this is coming from. I also switched places between the controls and it is always the last one that is focused. The TabContainers don't have any fancy settings, this is basically what they look like:

<cc1:TabContainer ID="tabContainer" runat="server">
    <cc1:TabPanel runat="server" HeaderText="Header1" ID="tabPanel1" TabIndex="0">
        <HeaderTemplate>
            <asp:Label ID="lblTab1" runat="server" Text="Tab1"></asp:Label>
        </HeaderTemplate>
        <ContentTemplate>
            ... (anything goes here, it still doesn't work)
        </ContentTemplate>
    </cc1:TabPanel>
    <cc1:TabPanel runat="server" HeaderText="Header2" ID="tabPanel2" TabIndex="1">
        <HeaderTemplate>
            <asp:Label ID="lblTab2" EnableViewState="False" runat="server" Text="Tab2"></asp:Label>
        </HeaderTemplate>
        <ContentTemplate>
            ... (anything goes here, it still doesn't work)
        </ContentTemplate>
    </cc1:TabPanel>
</cc1:TabContainer>

我知道我可以在控件上设置焦点,我试过了,但页面首先滚动到选项卡容器,然后返回到焦点控件(它看起来不太好).我尝试将焦点设置为另一个控件:

I know I can set focus on a control, I tried it but the page first scrolls to the tab container and then returns to the focused control (it doesn't look good). I tried this to set the focus to another control:

<body id="main" onload="javascript:document.getElementById('lnkLogout').focus();">

这是 TabContainer 的标准行为吗?我怎样才能摆脱它?

Is this the standard behavior for the TabContainer? How can I get rid of it?

推荐答案

将脚本放在 ScriptManager 控件的正下方:

Place script below right after ScriptManager control:

<script type="text/javascript">
    Sys.Extended.UI.TabContainer.prototype._app_onload = function (sender, e) {
        if (this._cachedActiveTabIndex != -1) {
            this.set_activeTabIndex(this._cachedActiveTabIndex);
            this._cachedActiveTabIndex = -1;

            var activeTab = this.get_tabs()[this._activeTabIndex];
            if (activeTab) {
                activeTab._wasLoaded = true;
                //activeTab._setFocus(activeTab); -- disable focus on active tab in the last TabContainer
            }
        }
        this._loaded = true;
    }
</script>

这篇关于AjaxToolkit:页面最后一个 TabContainer 专注于页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆