IE6 textBox.focus(); causing “Unexpected call to method or property access”

倾然丶 夕夏残阳落幕 提交于 2019-12-24 09:22:56

问题


The issue is now resovled :) Thanks for everyone's help and attention!

I'm getting the JS error "Unexpected call to method or property access" in IE6 intermittently on the line "oAutoCompleteTextBox.focus();". Hopefully, someone has seen this issue before and can provide some insight on how to solve it. Below is the context of the usage.

$(document).ready(function () {
    ...
    oAutoCompleteTextBox = GetElement('<%=this.AutoCompleteTextBox.ClientID%>');
    ...
    SetupDefaultValues();
}

function SetupDefaultValues() {
    ...
    if(canFocus(oAutoCompleteTextBox)) {
        oAutoCompleteTextBox.focus();
    }
}

My 1st post on stackoverflow - YAY!


回答1:


OK, so the issue was that the jQuery $(document).ready() event isn't fired on updatepanel async postbacks. The solution is to refactor the function definition inside the ready() into an explicit function definition (i.e. function pageReady(){...}) and add the new pageReady() eventhandler to ASP.net Sys.WebForms.PageRequestManager endRequest event which is only fired on async postbacks.

So the code now looks like this:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(pageReady);
$(document).ready(pageReady);

function pageReady() {
    ...
    oAutoCompleteTextBox = GetElement('<%=this.AutoCompleteTextBox.ClientID%>');
    ...
    SetupDefaultValues();
}

function SetupDefaultValues() {
    ...
    if(canFocus(oAutoCompleteTextBox)) {
        oAutoCompleteTextBox.focus();
    }
}

Thanks for everyone's help and attention - took a while to figure out, I'm just glad it's resolved :)




回答2:


Is oAutoCompleteTextBox declared globally? You're setting it in the document.ready function but trying to use it in another function.




回答3:


are you sure its a textbox? what does "canFocus" function do? alert on that line, oAutoCompleteTextBox.tagName, then if it is "INPUT" alert .type, if it is "text" then you have problem :) knowing IE6, it might be a timing problem nothing but, if you call setupdefaultvalues in a settimeout of 10 seconds, i MIGHT work



来源:https://stackoverflow.com/questions/1971281/ie6-textbox-focus-causing-unexpected-call-to-method-or-property-access

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