在将代码加载到背后之后,加载javascript代码

在将代码加载到背后之后,加载javascript代码

问题描述:

我有一个在facebook平台上发布的网站,我正在使用C#.Net 2008,问题是我正在从javascript arary中的代码后面加载数组元素,并且在使用以下javascript代码来加载elelment元素:

I have a web site released at facebook platform, i am using C# .Net 2008, the problem is that i am loading an array elements from code behind in javascript arary and i am loading elelment element using the following javascript code :

ArList = new Array('<%=ListOfWords[0]%>','<%=ListOfWords[1]%>','<%=ListOfWords[2]%>','<%=ListOfWords[2]%>');

当我从数组中调用元素时,出现如下问题:

the problem that when i call an element from the array as follows :

document.getElementById("WordDiv").innerHTML = ArList [0];

该元素未设置值,尽管后面代码中的数组具有值,但我不知道为什么未设置该数组元素的值?在某些情况下,我发现它加载了值,并且一切正常,因此可能是渲染时出现问题,因此在客户端看不到背后代码的值吗?还是问题出在哪里?当我在IE中跟踪该应用程序时,我发现状态栏报告了一个javascript错误,然后消失了并说完成,当状态栏中出现黄色提示时,我单击了它,并注意到消息说:对象预期.

The element is not set with the value inspite the array in the code behind has values and i don't know why the value of the array element is not set ? and in some cases i found it loaded with value and everything go right so may be it's a problem in rendering so the value of code behind is not seen in client side ? or where is the problem come ? and when i traced the application in IE i found the status bar report a javascript error then disappered and say done and when the yellow allert appears in the status bar i have clicked it and noticed the message says : object expected.

现在的问题是在body标签的onload事件中,我在javascript中调用了一个函数,该函数使用来自数组后面代码的值初始化javascript数组,问题是在某些情况下,该函数未按我跟踪的方式输入通过在函数的开头放置警报,我发现当未填充javascript数组时,由于未显示警报,因此未输入函数的代码,所以我不知道如何强制DOM进入此函数我在代码示例的标记中将其称为:javascript代码:

The problem now is that in onload event of the body tag i call a function in the javascript that intialize the javascript array with values from code behind array and the problem is that in some cases the function is not entered as i traced it by putting an alert in the begining of the function and i found that when the javascript array is not filled the code of the function is not entered as the alert is not showed so i don't know how to force the DOM to enter this function which i call it in the tag here sample of the code: javascript code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <html xmlns="http://www.w3.org/1999/xhtml">
     <head runat="server">         
     </head>
     <body onload="IntializeArr(); return false;">
     <form id="form1" runat="server" >
     ..........Some Controls...............
    </form>
    <script type="text/javascript" language="javascript"> 
    var TList;
    var BList;
       function IntializeArr()
     {       
        TList = new Array('<%=ListofT[0]%>','<%=ListofT[1]%>','<%=ListofT[2]%>','<%=ListofT[3]%>','<%=ListofT[4]%>','<%=ListofT[5]%>','<%=ListofT[6]%>','<%=ListofT[7]%>','<%=ListofT[8]%>','<%=ListofT[9]%>');
        BList = new Array('<%=ListOfB[0]%>','<%=ListOfB[1]%>','<%=ListOfB[2]%>','<%=ListOfB[3]%>','<%=ListOfB[4]%>','<%=ListOfB[5]%>','<%=ListOfB[6]%>','<%=ListOfB[7]%>','<%=ListOfB[8]%>','<%=ListOfB[9]%>');        
     }
    </script>
    </body>
    </html>

C#代码:

public string[] ListOfB = new string[15];
public string[] ListofT = new string[15];

数组的代码是从数据库返回的数据中填充的,它们是填充的,我已经跟踪了它们,每次都填充了它们,我发现javascript的问题我不知道这是来自Facebook平台还是从我的代码中获取,但是我认为不是从我的代码中获取,因为我在标签的onload中调用了一个函数,而该函数未输入,这就是问题所在,所以有人可以帮助我吗

And the code behind array is filled from data returned from database and they are filled i have traced them and each time and they are filled and i found that the problem from javascript i don't know if it is from facebook platform or from my code but i think that it is not from my code as the problem that i call a function in the onload of the tag and the function is not entered and this is the problem so can any one help me please

希望我会在沮丧时找到解决方法

Hope that i will find a solution as i got depressed

如果未调用IntializeArr()函数,则很可能是页面中的javascript错误,并且很可能是由于ListofT或ListofB数组.

If the IntializeArr() function is not being called, it is most likely a javascript error in the page, and most likely caused by some invalid javascript characters in the ListofT or ListofB arrays.

您应该转义任何单引号或换行符.

You should be escaping any single quotes or newlines.

最简单的检查方法是在页面加载后仅在浏览器中查看源代码".查看脚本,查找放置了哪些值,然后应该查看是否有任何错误.

Easiest way to check is to just "view source" in the browser once the page has loaded. Look down to your script and find what values were put it and you should see if there were any errors.