开发者

post back occurs javascript listbox items lost in asp.net

i have 10 list boxes in my aspx page for all 10 list boxes same function is using for some buttons i want to add listbox data to grid can you help me my java script code shown below

function MoveItem(ctrlSource, ctrlTarget) {

   var Source = document.getElementById(ctrlSource);

   var Target = document.getElementById(ctrlTarget);



   if ((Source != null) && (Target != null)) {

       while ( Source.options.selectedIndex >= 0 ) {

           var newOption = new Option()开发者_如何学运维; // Create a new instance of ListItem

           newOption.text = Source.options[Source.options.selectedIndex].text;

           newOption.value = Source.options[Source.options.selectedIndex].value;



           Target.options[Target.length] = newOption; //Append the item in Target

           Source.remove(Source.options.selectedIndex);  //Remove the item from Source

       }

   }

}

i tried a javascript above code to move items between listbox using html input button problem when i trying to save listbox.items.count giving 0 can anyone tell me why this happening and also when post back occurs listbox items lost.


Dear,
This is a normal, any thing changed client side to the list box will not be reflected on the server side. you can add an onclientclick event on the button and read the items from the listbox client side and save them using AJAX, or you can read the items from the listbox client side and put them in a hidden field as a string and you can read the value of the hidden field server side.

you can read all the item from the client side, and format them in your own format as a string.

then add an asp hidden field on the page, and client side put the string that you have in the hidden field value property.

now you can access the string from the onclick event on the server side and extract the items of the list boxes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜