Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Passing Array to javascript from aspx.cs page

Passing Array to javascript from aspx.cs page

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-netdata-structureshelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amarnath n n
    wrote on last edited by
    #1

    Hi All I have one doubt,how to pass array to javascript function from asp.net aspx.cs page.can you help me? Thanks in Advance:rose:

    A M A 3 Replies Last reply
    0
    • A amarnath n n

      Hi All I have one doubt,how to pass array to javascript function from asp.net aspx.cs page.can you help me? Thanks in Advance:rose:

      A Offline
      A Offline
      Arindam Sinha
      wrote on last edited by
      #2

      You can send it through embeding server side code -

      var jsVariable = '<%= ServerSideVaraible %>';

      Anothe approach could be you can use some hidden variable -

      <asp:HiddenField ID="HiddenField1" runat="server" />

      Once the value is set in the server side you can get the value in javascript -

      var sValue = document.getElementById('HiddenField1').value;

      If you use AJAX then it would altogether different. Anyway, let me know if you need any further detail. :)

      Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.

      M 1 Reply Last reply
      0
      • A Arindam Sinha

        You can send it through embeding server side code -

        var jsVariable = '<%= ServerSideVaraible %>';

        Anothe approach could be you can use some hidden variable -

        <asp:HiddenField ID="HiddenField1" runat="server" />

        Once the value is set in the server side you can get the value in javascript -

        var sValue = document.getElementById('HiddenField1').value;

        If you use AJAX then it would altogether different. Anyway, let me know if you need any further detail. :)

        Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.

        M Offline
        M Offline
        Manas Bhardwaj
        wrote on last edited by
        #3

        Arindam Sinha wrote:

        Anothe approach could be you can use some hidden variable -

        How will you hold the array in the value of hidden varaible? :doh:

        Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

        A 1 Reply Last reply
        0
        • A amarnath n n

          Hi All I have one doubt,how to pass array to javascript function from asp.net aspx.cs page.can you help me? Thanks in Advance:rose:

          M Offline
          M Offline
          Manas Bhardwaj
          wrote on last edited by
          #4

          You might look at this:

          ClientScript.RegisterArrayDeclaration("myarray", "'code project','manas','bhardwaj'");

          Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

          1 Reply Last reply
          0
          • A amarnath n n

            Hi All I have one doubt,how to pass array to javascript function from asp.net aspx.cs page.can you help me? Thanks in Advance:rose:

            A Offline
            A Offline
            Abhishek Sur
            wrote on last edited by
            #5

            use var x = ["24", "43", "56"]; But I wonder why do you require to pass an array. You can pass the data in a hidden field, and get the data through javascript. You can use comma separated string to show your data. :thumbsup:

            Abhishek Sur


            My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

            **Don't forget to click "Good Answer" if you like to.

            1 Reply Last reply
            0
            • M Manas Bhardwaj

              Arindam Sinha wrote:

              Anothe approach could be you can use some hidden variable -

              How will you hold the array in the value of hidden varaible? :doh:

              Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

              A Offline
              A Offline
              Arindam Sinha
              wrote on last edited by
              #6

              Manas...I think any delimeter separator string would suffice... :laugh:

              Regards, Arindam Sinha MyBlog - http://arindamsinha.wordpress.com/ Please give your feedback on this answer.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups