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. Filling Dropdown using Javascript

Filling Dropdown using Javascript

Scheduled Pinned Locked Moved ASP.NET
javascriptdatabasesysadmin
10 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.
  • M Offline
    M Offline
    Mahesh J
    wrote on last edited by
    #1

    Hi, I am filling the dropdown using javascript. I have given the selected index also. But after any server event the filled values are gone. What could be the reason. Thanks.

    T R V 3 Replies Last reply
    0
    • M Mahesh J

      Hi, I am filling the dropdown using javascript. I have given the selected index also. But after any server event the filled values are gone. What could be the reason. Thanks.

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      The reason is that asp.net uses something called ViewState[^]. If you modify the html on the client via javascrit, that html is gone when the page posts back to the server.

      I didn't get any requirements for the signature

      M 1 Reply Last reply
      0
      • M Mahesh J

        Hi, I am filling the dropdown using javascript. I have given the selected index also. But after any server event the filled values are gone. What could be the reason. Thanks.

        R Offline
        R Offline
        r aa j
        wrote on last edited by
        #3

        newOpt = document.createElement("OPTION"); newOpt = new Option(nodval,nodval); libox.options.add(newOpt); try this..

        Rajendran.AL

        M 1 Reply Last reply
        0
        • T ToddHileHoffer

          The reason is that asp.net uses something called ViewState[^]. If you modify the html on the client via javascrit, that html is gone when the page posts back to the server.

          I didn't get any requirements for the signature

          M Offline
          M Offline
          Mahesh J
          wrote on last edited by
          #4

          Hi, Thanks for your reply. Please tell me the solution. Thanks.

          T 1 Reply Last reply
          0
          • R r aa j

            newOpt = document.createElement("OPTION"); newOpt = new Option(nodval,nodval); libox.options.add(newOpt); try this..

            Rajendran.AL

            M Offline
            M Offline
            Mahesh J
            wrote on last edited by
            #5

            Hi, Thanks. I have used that option only. But still after the postback the filled items gone.

            R 1 Reply Last reply
            0
            • M Mahesh J

              Hi, Thanks. I have used that option only. But still after the postback the filled items gone.

              R Offline
              R Offline
              r aa j
              wrote on last edited by
              #6

              send me your code

              Rajendran.AL

              M 1 Reply Last reply
              0
              • R r aa j

                send me your code

                Rajendran.AL

                M Offline
                M Offline
                Mahesh J
                wrote on last edited by
                #7

                var ddlVendor = window.opener.document.getElementById(gId); //Clears the combo box contents. for (var count = ddlVendor.options.length-1; count >-1; count--) { ddlVendor.options[count] = null; } var vendorNodes = listNode.getElementsByTagName('Table1/Name'); var vendorIds = listNode.getElementsByTagName('Table1/Id'); var textValue; var idValue; var optionItem; //Add new vendors list to the vendors combo box. for (var count = 0; count < vendorNodes.length; count++) { textValue = GetInnerText(vendorNodes[count]); idValue = GetInnerText(vendorIds[count]); var newOption = window.opener.document.createElement('OPTION'); newOption.text = textValue; newOption.value = idValue; ddlVendor.options.add(newOption); } ddlVendor.selectedIndex = count-1;

                R 1 Reply Last reply
                0
                • M Mahesh J

                  var ddlVendor = window.opener.document.getElementById(gId); //Clears the combo box contents. for (var count = ddlVendor.options.length-1; count >-1; count--) { ddlVendor.options[count] = null; } var vendorNodes = listNode.getElementsByTagName('Table1/Name'); var vendorIds = listNode.getElementsByTagName('Table1/Id'); var textValue; var idValue; var optionItem; //Add new vendors list to the vendors combo box. for (var count = 0; count < vendorNodes.length; count++) { textValue = GetInnerText(vendorNodes[count]); idValue = GetInnerText(vendorIds[count]); var newOption = window.opener.document.createElement('OPTION'); newOption.text = textValue; newOption.value = idValue; ddlVendor.options.add(newOption); } ddlVendor.selectedIndex = count-1;

                  R Offline
                  R Offline
                  r aa j
                  wrote on last edited by
                  #8

                  check the for loop....length and count condition..

                  Rajendran.AL

                  1 Reply Last reply
                  0
                  • M Mahesh J

                    Hi, Thanks for your reply. Please tell me the solution. Thanks.

                    T Offline
                    T Offline
                    ToddHileHoffer
                    wrote on last edited by
                    #9

                    If you are using .net 2.0 or higher. I suggest using AJAX and writing server code to populate the drop down. Do you understand why it is that if you populate a dropdown with javascript you're going to have to re-populate that list after every postback?

                    I didn't get any requirements for the signature

                    1 Reply Last reply
                    0
                    • M Mahesh J

                      Hi, I am filling the dropdown using javascript. I have given the selected index also. But after any server event the filled values are gone. What could be the reason. Thanks.

                      V Offline
                      V Offline
                      Vasudevan Deepak Kumar
                      wrote on last edited by
                      #10

                      Mahesh.J wrote:

                      any server event

                      The server event resurrects the values from a statebag called ViewState. You ought to rebind your JavaScript dropdown again.

                      Vasudevan Deepak Kumar Personal Homepage
                      Tech Gossips
                      All the world's a stage, And all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts... --William Shakespeare

                      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