客户端更新后更新Web服务器控件 [英] Updating webserver controls after clientside update
问题描述
我的页面中有2个asp:listboxes和2个按钮.一个按钮是普通的HTML按钮,另一个按钮是asp:button.
我在第一个列表框中有一个值列表.在我的html按钮单击上,使用jQuery编写的函数将值复制/移动到第二个列表框.但是当我单击检查第二个列表框中的值的asp:button时,它将显示列表框中的项目计数为0.
有什么办法可以让我在asp:button click上获得第二个列表框的值吗?
谢谢,
Daion
Hi,
I have 2 asp:listboxes and 2 buttons in my page. one button is a normal HTML button and the other is an asp:button.
I''ve a list of values in the first listbox. on my html button click, the values are being copied/moved to the second list box using a function written in jQuery. But when i click on my asp:button which check the values inside second listbox, it shows the count of items in the listbox as 0.
Is there any way i can get the values of second listbox on the asp:button click?
Thanks,
Daion
推荐答案
下拉列表,列表框,标签等已进行序列化,并且状态存储在viewstate中.因此,当您执行回发时,将重新创建控件,并从viewstate加载值.因此,您无法在第二个列表框中看到通过JavaScript添加的项目.
使其正常工作的唯一方法是在页面上保留一个隐藏字段.从listbox1中选择的项目作为逗号分隔的列表添加到您将其添加到第二个列表框中的相同功能的隐藏字段中,然后在回发时在服务器端访问此隐藏字段中的值.
Dropdown, list box, labels etc. are serialized and state is stored in viewstate. So when you do the postback the controls are recreated and the values are loaded from viewstate. Hence you cannot see the items added through JavaScript in second listbox.
The only way to get it working is have a hidden field on the page. Add the selected items from listbox1 as comma separated list in the hidden field in the same function where you are adding it to second listbox and then access the values from this hidden field at server side on postback.
这篇关于客户端更新后更新Web服务器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!