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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to count listbox items in codebehind when i add item using Javascript!

How to count listbox items in codebehind when i add item using Javascript!

Scheduled Pinned Locked Moved ASP.NET
helpjavascriptsysadmintutorial
3 Posts 3 Posters 1 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.
  • C Offline
    C Offline
    Chetan visodiya
    wrote on last edited by
    #1

    Hi! In facts, my problem is to access the info in the server side! If i use ListBox.Items... It is not working but I really have two rows in my listbox... Look this: This is my javascript code: First i select the item in listbox1 then click on add button so add seleccted item into listbox2 and remove selected item from listbox1 using javascript. function fctAjoutAssigne() { var mylist = document.getElementById("ListBox1") var mylist2 = document.getElementById("ListBox2") mylist2.options[mylist2.length]= new Option(mylist.options[mylist.selectedIndex].text,mylist.options[mylist.selectedIndex].value); mylist.remove(mylist.selectedIndex) } and at last i click on save button. code of save button is : For i = 0 To ListBox2.Items.Count - 1 strAssignation &= ListBox2.Items(i).Value & "," strNomAssigne &= ListBox2.Items(i).Text & ";" Next But ListBox2.Items.Count = 0 even If I have two items in my list... Amazing... if you know then tell me how to fix this. chetan patel

    A T 2 Replies Last reply
    0
    • C Chetan visodiya

      Hi! In facts, my problem is to access the info in the server side! If i use ListBox.Items... It is not working but I really have two rows in my listbox... Look this: This is my javascript code: First i select the item in listbox1 then click on add button so add seleccted item into listbox2 and remove selected item from listbox1 using javascript. function fctAjoutAssigne() { var mylist = document.getElementById("ListBox1") var mylist2 = document.getElementById("ListBox2") mylist2.options[mylist2.length]= new Option(mylist.options[mylist.selectedIndex].text,mylist.options[mylist.selectedIndex].value); mylist.remove(mylist.selectedIndex) } and at last i click on save button. code of save button is : For i = 0 To ListBox2.Items.Count - 1 strAssignation &= ListBox2.Items(i).Value & "," strNomAssigne &= ListBox2.Items(i).Text & ";" Next But ListBox2.Items.Count = 0 even If I have two items in my list... Amazing... if you know then tell me how to fix this. chetan patel

      A Offline
      A Offline
      alexfromto
      wrote on last edited by
      #2

      Hi man. Why don't you use code behind to populate your ListBox2 instead of JavaScript? I'm not sure how your code works but I think what happens is: 1. When you add new items with JavaScript it works no problem 2. When you clisk Save button it submits the page and you are loosing your valuse in the ListBox2. Seems like Posting is your problem.

      1 Reply Last reply
      0
      • C Chetan visodiya

        Hi! In facts, my problem is to access the info in the server side! If i use ListBox.Items... It is not working but I really have two rows in my listbox... Look this: This is my javascript code: First i select the item in listbox1 then click on add button so add seleccted item into listbox2 and remove selected item from listbox1 using javascript. function fctAjoutAssigne() { var mylist = document.getElementById("ListBox1") var mylist2 = document.getElementById("ListBox2") mylist2.options[mylist2.length]= new Option(mylist.options[mylist.selectedIndex].text,mylist.options[mylist.selectedIndex].value); mylist.remove(mylist.selectedIndex) } and at last i click on save button. code of save button is : For i = 0 To ListBox2.Items.Count - 1 strAssignation &= ListBox2.Items(i).Value & "," strNomAssigne &= ListBox2.Items(i).Text & ";" Next But ListBox2.Items.Count = 0 even If I have two items in my list... Amazing... if you know then tell me how to fix this. chetan patel

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

        Sounds like you need some AJAX!


        how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

        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