Pregunta

I have almost the exact same question as at the following post (and I tried both of the answers, but neither works), except I'm not worried about whether the TabContainer is last on the page or not - I want to prevent the page from skipping up or down to any tabcontainer when the updatePanel containing the tabcontainer gets updated. (Of course, I guess it's actually a TabPanel - the active one - getting the focus, not really the TabContainer.)

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

As the poster says at above link, I have not explicitly set any focus, so I don't know why focus is getting set to my tabPanel. When I debug, I can see that there is some javascript loaded by Ajax that sets focus.

I guess what I want to do, unless there is some property I can set (autofocus=false ?) is override whatever ajax javascript is being executed so that the focus does not get set.

Not sure how to go about this, however. Is that javascript source published somewhere, so I can copy it, comment out the focus instruction, and override?

UPDATE

I was debugging the release version of the ajax script. I didn't realize there was a debug version available. I had debugging on in web.config, but apparently the ScriptManager also needs ScriptMode="Debug"; when I set that, I get debug versions of internal ajax code. I'm not done yet, but I think should now be able to find the offensive code that sets the focus without me asking it to set any focus, and override it. I'll post an answer when I'm done.

¿Fue útil?

Solución

Finally fixed it myself by debugging ajax, finding the offensive code and overriding it.

If anyone has the same problem, this is AjaxCotnrolToolkit version 4.1.60501.0, and the below resides in Tabs.Tabs.js; just stick this script on your page to stop the annoying autofocus.

I've turned it off altogether for now, but of course it could be turned off conditionally if that's what you want.

The only difference between the below and the original method is the commented line.

    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);     // the only change made to this prototype
                }
            }
            this._loaded = true;
        }

EDIT: Wow, I just noticed this is exactly the same code as was provided at the original link I posted above. I guess I must have made some stupid mistake before that prevented it from working for me.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top