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

问题描述

我使用一个页面上有多个TabContainer的在ASP.NET项目中,我注意到一个很奇怪的现象:当页面加载的焦点跳转到页面上的最后一个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的重点是在页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 23:38