Populating Javascript array from vb.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MW

    #1

    Populating Javascript array from vb.net

    How can I poplute a javascript array from vb.net? I would prefer to do this
    from codebehind.

    Michael


  • Teemu Keiski

    #2
    Re: Populating Javascript array from vb.net

    Hi,

    You an use Page.RegisterAr rayDeclaration method for that.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist



    "MW" <Please@NoSpam. com> wrote in message
    news:u8FvQSaLEH A.4052@TK2MSFTN GP11.phx.gbl...[color=blue]
    > How can I poplute a javascript array from vb.net? I would prefer to do[/color]
    this[color=blue]
    > from codebehind.
    >
    > Michael
    >
    >[/color]


    Comment

    • David Jessee

      #3
      Re: Populating Javascript array from vb.net

      Create a String that represents the code and register it as a client script

      dim str as String = "<script>va r i=new
      Array();i[0]=234;i[1]=543;i[2]=598;</script>"
      page.RegisterCl ientScriptBlock (""myScript",st r)

      (this method does not show up in intellisense, but you can see it if you
      look at the page class through the object browser)

      "MW" <Please@NoSpam. com> wrote in message
      news:u8FvQSaLEH A.4052@TK2MSFTN GP11.phx.gbl...[color=blue]
      > How can I poplute a javascript array from vb.net? I would prefer to do[/color]
      this[color=blue]
      > from codebehind.
      >
      > Michael
      >
      >[/color]


      Comment

      • Ashish M Bhonkiya

        #4
        Re: Populating Javascript array from vb.net

        Hi,
        you can add the following code in your page to create an array also
        you can edit this code to add your on logic for assigning the values in to
        the array.

        Private Sub Page_Load(ByVal sender As Object, ByVal e As
        System.EventArg s)
        ' Put user code to initialize the page here
        Me.RegisterStar tupScript("SetF ocusScript",
        PopulateJavaScr iptArray())
        End Sub


        Private Function PopulateJavaScr iptArray() As String
        ' Declaring the Number of Items in the Array
        Dim noOfItems As Integer = 10
        Dim myJavaScript As StringBuilder = New StringBuilder()
        myJavaScript.Ap pend("<script language='Javas cript'>")
        myJavaScript.Ap pend(" var myArrayInJavaSc ript = new Array("+
        noOfItems +");")
        myJavaScript.Ap pend(" myArrayInJavaSc ript[5] ='Hello
        There...!!';")
        myJavaScript.Ap pend(" alert(myArrayIn JavaScript[5]);")
        myJavaScript.Ap pend("</script>")
        Return myJavaScript.To String()
        End Function

        HTH
        Regards
        Ashish M Bhonkiya


        "MW" <Please@NoSpam. com> wrote in message
        news:u8FvQSaLEH A.4052@TK2MSFTN GP11.phx.gbl...[color=blue]
        > How can I poplute a javascript array from vb.net? I would prefer to do[/color]
        this[color=blue]
        > from codebehind.
        >
        > Michael
        >
        >[/color]


        Comment

        • avnrao

          #5
          Re: Populating Javascript array from vb.net

          check this code

          String scriptString = "<script language=JavaSc ript> function doClick() {";
          scriptString += "for(var index=0;index < myArray.length; index++)";
          scriptString += " myArray[index].show(); } <";
          scriptString += "/" + "script>";

          RegisterStartup Script("arraySc ript", scriptString);
          RegisterArrayDe claration("myAr ray", "new obj('x'),new obj('y'),new
          obj('z')");

          you can declare your array using your values.

          Av.

          "MW" <Please@NoSpam. com> wrote in message
          news:u8FvQSaLEH A.4052@TK2MSFTN GP11.phx.gbl...[color=blue]
          > How can I poplute a javascript array from vb.net? I would prefer to do
          > this
          > from codebehind.
          >
          > Michael
          >
          >[/color]


          Comment

          Working...