开发者

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

开发者 https://www.devze.com 2022-12-15 12:30 出处:网络
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 \"oAutoCompleteTex

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();
  开发者_如何学JAVA  }
}

My 1st post on stackoverflow - YAY!


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消