如何在asp.net中保留/保留页面回发上ListBox的所有值? [英] How to persist / retain all the values of ListBox on the Page Postback in asp.net?

查看:88
本文介绍了如何在asp.net中保留/保留页面回发上ListBox的所有值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net中将页面回传中的列表框的所有值持久化?
例如,我们有一个列表框,并且使用javascript将一些值添加到其中,当用户单击下一步"按钮时,将执行验证,并且添加到列表框的值不会持久存在,而是所有值都消失了.因此,无论何时触发任何验证器或页面回发,都必须保留列表框中所有具有的值.

How to persist all the values of the listbox on page postback in asp.net?

For instance we have a listbox and some values are added into it using javascript, when ever user click on Next Button then validation is performed and the values added into listbox doesnot persist instead all the values are gone. So when ever any validator is fired or if the page postback, all the values with in the listbox must be retained.

推荐答案

一些值会添加到其中使用javascript

如果要使用Javascript在客户端添加少量值,则需要对其进行跟踪,并可能将其保留在隐藏"字段中.大约下一次回发,请使用隐藏字段将其重新填充.

Viewstate在这里不起作用,因为它适用于服务器端填充的普通列表框.由于您是在客户端添加数据的,因此您需要使用一些额外的代码来跟踪和更新它.
some values are added into it using javascript

If you are adding few values client side using Javascript then you need to track it and probably keep it in Hidden field. Next postback or so, re-populate it using the hidden field.

Viewstate wont work here as it works for normal listbox populated on server side. Since you added data on client side, you need to use some extra code to track and update it.


这篇关于如何在asp.net中保留/保留页面回发上ListBox的所有值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆