Javascript语言的ASP.NET [英] Javascript in asp .Net
问题描述
我收到WebResource错误在我asp.Net页:
VAR __pendingCallbacks =新的Array();微软JScript运行时错误:'阵'是未定义
我不知道什么可能导致这种情况发生。 JavaScript不本身的阵列部分?任何帮助将是AP preciated。
修改
问题是,这并不是code,我写的,它的建成在asp.Net页面结构。
修改
问题只出现在IE9中,只有当在IE9模式下运行(不兼容)
的 code:的
(这是动态生成code,遗憾的长度。问题是大约一半向下)
函数WebForm_PostBackOptions(的eventTarget,eventArgument,验证的ValidationGroup,actionUrl,trackFocus,clientSubmit){
this.eventTarget =的eventTarget;
this.eventArgument = eventArgument;
this.validation =验证;
this.validationGroup =的ValidationGroup;
this.actionUrl = actionUrl;
this.trackFocus = trackFocus;
this.clientSubmit = clientSubmit;
}
功能WebForm_DoPostBackWithOptions(选项){
VAR为ValidationResult = TRUE;
如果(options.validation){
如果(typeof运算(Page_ClientValidate)=='功能'){
为ValidationResult = Page_ClientValidate(options.validationGroup);
}
}
如果(为ValidationResult){
如果((typeof运算(options.actionUrl)=未定义)及!&放大器;!(options.actionUrl =空)及及(options.actionUrl.length大于0)){
theForm.action = options.actionUrl;
}
如果(options.trackFocus){
VAR lastFocus = theForm.elements [__ LASTFOCUS];
如果((typeof运算(lastFocus)=未定义)及!&安培;!(lastFocus = NULL)){
如果(typeof运算(document.activeElement)==未定义){
lastFocus.value = options.eventTarget;
}
其他{
VAR激活= document.activeElement;
如果((typeof运算(活性)=未定义)及!&放大器;!(活性=空)){
如果((typeof运算(active.id)=未定义)及!及(active.id =空)及!及(active.id.length大于0)){
lastFocus.value = active.id;
}
否则,如果(typeof运算(active.name)!=未定义){
lastFocus.value = active.name;
}
}
}
}
}
}
如果(options.clientSubmit){
__doPostBack(options.eventTarget,options.eventArgument);
}
}
VAR __pendingCallbacks =新的Array();
变种__synchronousCallBackIndex = -1;
功能WebForm_DoCallback(的eventTarget,eventArgument,eventCallback,背景,errorCallback,useAsync){
VAR POSTDATA = __theFormPostData +
__CALLBACKID =+ WebForm_En codeCallback(的eventTarget)+
&放大器; __ CALLBACKPARAM =+ WebForm_En codeCallback(eventArgument);
如果(theForm [__ EVENTVALIDATION]){
POSTDATA + =&放大器; __ EVENTVALIDATION =+ WebForm_En codeCallback(theForm [__ EVENTVALIDATION]值);
}
VAR xmlRequest,E;
尝试{
xmlRequest =新XMLHtt prequest();
}
赶上(E){
尝试{
xmlRequest =新的ActiveXObject(Microsoft.XMLHTTP);
}
赶上(E){
}
}
VAR setRequestHeaderMethodExists = TRUE;
尝试{
setRequestHeaderMethodExists =(xmlRequest&安培;&安培; xmlRequest.setRequestHeader);
}
赶上(E){}
VAR回调=新的对象();
callback.eventCallback = eventCallback;
callback.context =背景;
callback.errorCallback = errorCallback;
callback.async = useAsync;
VAR callbackIndex = WebForm_FillFirstAvailableSlot(__ pendingCallbacks,回调);
如果(!useAsync){
如果(__synchronousCallBackIndex!= -1){
__pendingCallbacks [__ synchronousCallBackIndex] = NULL;
}
__synchronousCallBackIndex = callbackIndex;
}
如果(setRequestHeaderMethodExists){
xmlRequest.onreadystatechange = WebForm_CallbackComplete;
callback.xmlRequest = xmlRequest;
xmlRequest.open(POST,theForm.action,真正的);
xmlRequest.setRequestHeader(内容类型,应用程序/ x-WWW的形式urlen codeD;字符集= UTF-8);
xmlRequest.send(POSTDATA);
返回;
}
callback.xmlRequest =新的对象();
VAR callbackFrameID =__CALLBACKFRAME+ callbackIndex;
VAR xmlRequestFrame = document.frames [callbackFrameID]
如果(!xmlRequestFrame){
xmlRequestFrame = document.createElement方法(IFRAME);
xmlRequestFrame.width =1;
xmlRequestFrame.height =1;
xmlRequestFrame.frameBorder =0;
xmlRequestFrame.id = callbackFrameID;
xmlRequestFrame.name = callbackFrameID;
xmlRequestFrame.style.position =绝对;
xmlRequestFrame.style.top =-100px
xmlRequestFrame.style.left =-100px;
尝试{
如果(callBackFrameUrl){
xmlRequestFrame.src = callBackFrameUrl;
}
}
赶上(E){}
document.body.appendChild(xmlRequestFrame);
}
VAR间隔= window.setInterval(函数(){
xmlRequestFrame = document.frames [callbackFrameID]
如果(xmlRequestFrame&安培;&安培; xmlRequestFrame.document){
window.clearInterval(间隔);
xmlRequestFrame.document.write();
xmlRequestFrame.document.close();
xmlRequestFrame.document.write('< HTML><身体GT;<形式方法=邮报><输入类型=隐藏的名字=__ CALLBACKLOADSCRIPTVALUE =T>< /表> < /身体GT;< / HTML>');
xmlRequestFrame.document.close();
xmlRequestFrame.document.forms [0] .action = theForm.action;
变种数= __theFormPostCollection.length;
VAR元素;
对于(VAR I = 0; I<计数;我++){
元素= __theFormPostCollection [I]
如果(元素){
变种的FieldElement = xmlRequestFrame.document.createElement(INPUT);
fieldElement.type =隐藏;
fieldElement.name = element.name;
fieldElement.value = element.value;
xmlRequestFrame.document.forms [0] .appendChild(的FieldElement);
}
}
变种callbackIdFieldElement = xmlRequestFrame.document.createElement(INPUT);
callbackIdFieldElement.type =隐藏;
callbackIdFieldElement.name =__CALLBACKID;
callbackIdFieldElement.value =的eventTarget;
xmlRequestFrame.document.forms [0] .appendChild(callbackIdFieldElement);
变种callbackParamFieldElement = xmlRequestFrame.document.createElement(INPUT);
callbackParamFieldElement.type =隐藏;
callbackParamFieldElement.name =__CALLBACKPARAM;
callbackParamFieldElement.value = eventArgument;
xmlRequestFrame.document.forms [0] .appendChild(callbackParamFieldElement);
如果(theForm [__ EVENTVALIDATION]){
变种callbackValidationFieldElement = xmlRequestFrame.document.createElement(INPUT);
callbackValidationFieldElement.type =隐藏;
callbackValidationFieldElement.name =__EVENTVALIDATION;
callbackValidationFieldElement.value = theForm [__ EVENTVALIDATION]值。
xmlRequestFrame.document.forms [0] .appendChild(callbackValidationFieldElement);
}
变种callbackIndexFieldElement = xmlRequestFrame.document.createElement(INPUT);
callbackIndexFieldElement.type =隐藏;
callbackIndexFieldElement.name =__CALLBACKINDEX;
callbackIndexFieldElement.value = callbackIndex;
xmlRequestFrame.document.forms [0] .appendChild(callbackIndexFieldElement);
xmlRequestFrame.document.forms [0] .submit();
}
},10);
}
这是因为我们有这个设置
<可折叠的面板>
< IFRAME>
<脚本>
< / SCRIPT>
< / IFRAME>
< /可折叠面板>
在页面加载后,正在显示面板迫使iframe中的脚本通过DOM拖动装载的JavaScript库之前。这似乎是在变化的IE9制成。我还没有罚款解决这个问题的一种方式,但至少我知道的原因。临时解决方法是使用的情况下,任何人meta标签运行到这个问题,迫使网页的兼容IE8。
I'm getting WebResource error in my asp.Net page:
var __pendingCallbacks = new Array();
Microsoft JScript runtime error: 'Array' is undefined
I have no idea what might cause this to happen. Isn't Array part of Javascript itself? Any help would be appreciated.
EDIT The problem is that this isn't code that I wrote, it's built into the page structure in asp.Net.
EDIT The problem only occurs in IE9 and only when run in IE9 mode (not compatibility)
Code: (This is dynamically generated code, sorry for the length. Problem is about halfway down)
function WebForm_PostBackOptions(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit) {
this.eventTarget = eventTarget;
this.eventArgument = eventArgument;
this.validation = validation;
this.validationGroup = validationGroup;
this.actionUrl = actionUrl;
this.trackFocus = trackFocus;
this.clientSubmit = clientSubmit;
}
function WebForm_DoPostBackWithOptions(options) {
var validationResult = true;
if (options.validation) {
if (typeof(Page_ClientValidate) == 'function') {
validationResult = Page_ClientValidate(options.validationGroup);
}
}
if (validationResult) {
if ((typeof(options.actionUrl) != "undefined") && (options.actionUrl != null) && (options.actionUrl.length > 0)) {
theForm.action = options.actionUrl;
}
if (options.trackFocus) {
var lastFocus = theForm.elements["__LASTFOCUS"];
if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) {
if (typeof(document.activeElement) == "undefined") {
lastFocus.value = options.eventTarget;
}
else {
var active = document.activeElement;
if ((typeof(active) != "undefined") && (active != null)) {
if ((typeof(active.id) != "undefined") && (active.id != null) && (active.id.length > 0)) {
lastFocus.value = active.id;
}
else if (typeof(active.name) != "undefined") {
lastFocus.value = active.name;
}
}
}
}
}
}
if (options.clientSubmit) {
__doPostBack(options.eventTarget, options.eventArgument);
}
}
var __pendingCallbacks = new Array();
var __synchronousCallBackIndex = -1;
function WebForm_DoCallback(eventTarget, eventArgument, eventCallback, context, errorCallback, useAsync) {
var postData = __theFormPostData +
"__CALLBACKID=" + WebForm_EncodeCallback(eventTarget) +
"&__CALLBACKPARAM=" + WebForm_EncodeCallback(eventArgument);
if (theForm["__EVENTVALIDATION"]) {
postData += "&__EVENTVALIDATION=" + WebForm_EncodeCallback(theForm["__EVENTVALIDATION"].value);
}
var xmlRequest,e;
try {
xmlRequest = new XMLHttpRequest();
}
catch(e) {
try {
xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
}
}
var setRequestHeaderMethodExists = true;
try {
setRequestHeaderMethodExists = (xmlRequest && xmlRequest.setRequestHeader);
}
catch(e) {}
var callback = new Object();
callback.eventCallback = eventCallback;
callback.context = context;
callback.errorCallback = errorCallback;
callback.async = useAsync;
var callbackIndex = WebForm_FillFirstAvailableSlot(__pendingCallbacks, callback);
if (!useAsync) {
if (__synchronousCallBackIndex != -1) {
__pendingCallbacks[__synchronousCallBackIndex] = null;
}
__synchronousCallBackIndex = callbackIndex;
}
if (setRequestHeaderMethodExists) {
xmlRequest.onreadystatechange = WebForm_CallbackComplete;
callback.xmlRequest = xmlRequest;
xmlRequest.open("POST", theForm.action, true);
xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
xmlRequest.send(postData);
return;
}
callback.xmlRequest = new Object();
var callbackFrameID = "__CALLBACKFRAME" + callbackIndex;
var xmlRequestFrame = document.frames[callbackFrameID];
if (!xmlRequestFrame) {
xmlRequestFrame = document.createElement("IFRAME");
xmlRequestFrame.width = "1";
xmlRequestFrame.height = "1";
xmlRequestFrame.frameBorder = "0";
xmlRequestFrame.id = callbackFrameID;
xmlRequestFrame.name = callbackFrameID;
xmlRequestFrame.style.position = "absolute";
xmlRequestFrame.style.top = "-100px"
xmlRequestFrame.style.left = "-100px";
try {
if (callBackFrameUrl) {
xmlRequestFrame.src = callBackFrameUrl;
}
}
catch(e) {}
document.body.appendChild(xmlRequestFrame);
}
var interval = window.setInterval(function() {
xmlRequestFrame = document.frames[callbackFrameID];
if (xmlRequestFrame && xmlRequestFrame.document) {
window.clearInterval(interval);
xmlRequestFrame.document.write("");
xmlRequestFrame.document.close();
xmlRequestFrame.document.write('<html><body><form method="post"><input type="hidden" name="__CALLBACKLOADSCRIPT" value="t"></form></body></html>');
xmlRequestFrame.document.close();
xmlRequestFrame.document.forms[0].action = theForm.action;
var count = __theFormPostCollection.length;
var element;
for (var i = 0; i < count; i++) {
element = __theFormPostCollection[i];
if (element) {
var fieldElement = xmlRequestFrame.document.createElement("INPUT");
fieldElement.type = "hidden";
fieldElement.name = element.name;
fieldElement.value = element.value;
xmlRequestFrame.document.forms[0].appendChild(fieldElement);
}
}
var callbackIdFieldElement = xmlRequestFrame.document.createElement("INPUT");
callbackIdFieldElement.type = "hidden";
callbackIdFieldElement.name = "__CALLBACKID";
callbackIdFieldElement.value = eventTarget;
xmlRequestFrame.document.forms[0].appendChild(callbackIdFieldElement);
var callbackParamFieldElement = xmlRequestFrame.document.createElement("INPUT");
callbackParamFieldElement.type = "hidden";
callbackParamFieldElement.name = "__CALLBACKPARAM";
callbackParamFieldElement.value = eventArgument;
xmlRequestFrame.document.forms[0].appendChild(callbackParamFieldElement);
if (theForm["__EVENTVALIDATION"]) {
var callbackValidationFieldElement = xmlRequestFrame.document.createElement("INPUT");
callbackValidationFieldElement.type = "hidden";
callbackValidationFieldElement.name = "__EVENTVALIDATION";
callbackValidationFieldElement.value = theForm["__EVENTVALIDATION"].value;
xmlRequestFrame.document.forms[0].appendChild(callbackValidationFieldElement);
}
var callbackIndexFieldElement = xmlRequestFrame.document.createElement("INPUT");
callbackIndexFieldElement.type = "hidden";
callbackIndexFieldElement.name = "__CALLBACKINDEX";
callbackIndexFieldElement.value = callbackIndex;
xmlRequestFrame.document.forms[0].appendChild(callbackIndexFieldElement);
xmlRequestFrame.document.forms[0].submit();
}
}, 10);
}
This happens because we have this setup
<collapsible panel>
<iframe>
<script>
</script>
</iframe>
</collapsible panel>
When the page loads, the panel being shown forces the script inside the iframe to be dragged through the DOM before the javascript libraries are loaded. This seems to be a change in that was made for IE9. I have yet to fine a way around this issue but at least I know the cause. A temporary workaround is to force the compatibility of the page to IE8 using a meta tag in case anybody else runs into this issue.
这篇关于Javascript语言的ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!