AjaxToolkit: the last TabContainer on the page is focused on page load

前端 未结 5 2040
梦毁少年i
梦毁少年i 2021-01-18 07:00

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 TabContain

相关标签:
5条回答
  • 2021-01-18 07:08

    I had a similar problem, but I found a more simple solution.

    In the case you use a:

    <asp:toolkitscriptmanager ID="ScriptManager1" runat="server">
              </asp:toolkitscriptmanager>
    

    and more panel in the tab container ( 3 for example):

    <asp:tabcontainer runat="server" ID="tc1" ActiveTabIndex="0" > 
    
    <asp:TabPanel runat="server" ID="TB1" Height="250" >
    <asp:TabPanel runat="server" ID="TB1" Height="250" >
    <asp:TabPanel runat="server" ID="TB1" Height="250" >
    

    For example, you can use the property:

     ActiveTabIndex="0"
    

    OR

    tc1.ActiveTabIndex = 2 'code behind
    

    Where the integer is the ID of the tab you want to Focus.

    It works for me! I Hope I can Help someone!

    Enjoy

    0 讨论(0)
  • 2021-01-18 07:09

    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>
    
    0 讨论(0)
  • 2021-01-18 07:11

    Try this out. It helped me:

    window.Sys.Application.findComponent('<%=tabContainer.ClientID %>');
    
    tabContainer.set_activeTabIndex(1);  ( //Here set the id of the last tab that is the index of the last tab. Index will start with 0 upto last - 1 as in array.. )
    
    0 讨论(0)
  • 2021-01-18 07:15

    This is an old thread, but it never got resolved – here or in any of the other threads I found – and I had the same problem.

    I fixed it by putting my javascript in the body element: onload="scrollTo(0,0);"

    0 讨论(0)
  • 2021-01-18 07:26

    You can set focus server-side to avoid the page jumping around.

    Try this in Page_Load:

    PageUtility.SetFocus(foo);
    

    Also check you whether you are setting Page.MaintainScrollPositionOnPostback.

    Let me know if that helps.

    UPDATE - you can simply call .Focus() on whatever control you want to be in focus by default.

    eg: YourControlToFocus.Focus()

    0 讨论(0)
提交回复
热议问题