2012-12-04 4 views
1

ASP.net 클래스 ClientScript를 사용하여 배열을 aspx 페이지에 전달하려고합니다. 나는 이것을 수행하기 위해 이전 샘플을 성공적으로 완료했다 (아래 코드 샘플). 그러나 새로운 일과가 작동하지 않습니다. 차이점은 ClientScript 클래스입니다.VB.net 배열을 ClientScript 클래스를 사용하여 javascript로 전달

오류 ...

내 자바 코드는 "routeCoords는 정의되지 않는다"고 배열을 구축하고 스크립트를 등록

function newTest() { 
    var myArray = [ , ]; 
    var n = 0; 

    var recCount = routeCoords.length/15; 

    for (var i = 0; i < recCount ; i++) { 
     for (var s = 0; s < 15; s++) { 

      myArray[i, s] = routeCoords[n]; 
      n++; 

      alert(myArray[s], [i]); 
     } 
    } 
} 

vb.net을 .... 상태

' arrylist 
For p = 0 To arryLst.Count - 1 
    Page.ClientScript.RegisterArrayDeclaration("routeCoords", arryLst(p)) 
Next 

Dim strScript As String = "newTest();" 
ClientScript.RegisterStartupScript(GetType(Page), "newTest", strScript.ToString, True) 

배열이 vb.net에서 올바르게 채워집니다.

이것은 작업중인 샘플의 루틴입니다. g ...

VB.net 코드 :

For s = 0 To arryLst.Count - 1 
    Page.ClientScript.RegisterArrayDeclaration("parmTypeAry", arryLst(s)) 
Next 

자바 코드하십시오 드롭 다운리스트 상자를 채 웁니다

// Create and Element Object of type "option" 
    var opt = document.createElement("option"); 
    //Add the option element to the select item 
    listID.options.add(opt); 
    //Reading Element From Array 
    opt.text = parmTypeAry[s]; 

.

답변

0

여기 해결책이 있습니다. for 루프의 IF 조건을 사용하여 배열을 확인해야했습니다.

 for (i = 0; i < recCount; i++) { 
     // Array of arrays builds out each record. 
      if (!myArray[i]) 
       myArray[i] = [] 

      for (s = 0; s < 16; s++) { 
       // myArray[i] = new Array(14); 

       myArray[i][s] = routeCoordsAry[n]; 
       n++; 

       // alert("i=" + i + " s=" + s + " Val: " + (myArray[i][s])); 

      } 
      // var u = 4; 
      s = 0; 

     }