简体   繁体   English

JavaScript遍历aspx页面上的动态复选框

[英]JavaScript iterating through dynamic checkboxes on an aspx page

I have an aspx page that has dynamically created checkboxes. 我有一个动态创建复选框的aspx页面。 I'm trying to find a way to keep the state of this page (checkboxes that are checked to remain checked) when I hit the navigation button to go to the previous page. 我想找到一种方法,当我单击导航按钮转到上一页时,保持此页面的状态(选中的复选框保持选中状态)。 The problem is when I go from the previous page back to the page with the checkboxes I lose all of the values. 问题是当我从上一页返回到带有复选框的页面时,我丢失了所有值。 I understand why I lose them but I can't figure out how to retain them. 我了解为什么我会失去他们,但我不知道如何保留他们。 I was thinking about saving the ids of the boxes that are checked in a table but there just have to be a better way. 我正在考虑保存表中已选中的框的ID,但必须有更好的方法。 Any help would be appreciated. 任何帮助,将不胜感激。

If you want to keep the data for a long time, then storing in a table is absolutely the right approach. 如果要长时间保留数据,那么将数据存储在表中绝对是正确的方法。

If you only need to store them temporarily, then storing the data in a session variable would be a good option. 如果只需要临时存储它们,那么将数据存储在会话变量中将是一个不错的选择。

You could also store the values directly in a cookie, which would give you the option to use either server side code or javascript to set the checkboxes. 您也可以将值直接存储在cookie中,这将使您可以选择使用服务器端代码或javascript设置复选框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM