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

我的未来我决定 提交于 2019-12-01 17:11:24

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>
Alfa Thakkar

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.. )
dashbored

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);"

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()

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!