问题得到通过的jQuery在code后面添加列表框项目 [英] Problem getting list box items added through jquery in code behind

查看:110
本文介绍了问题得到通过的jQuery在code后面添加列表框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net列表框控件中,我通过使用一些code状填充使用Jquery项目..
$(#MylistBox)追加(<期权价值='someValue中'> Someitem< /选项>

I have a asp.net list box control in which i populate items using Jquery by using some code like .. $("#MylistBox").append("<option value='somevalue'>Someitem</option>

动态。
 但是当我使用落后于code
MylistBox.Items 总是显示计数 0 无论怎样很多项添加。

dynamically . but in code behind when i use MylistBox.Items is always showing Count 0 no matter how much items add.

任何人可以帮助我呢?

推荐答案

不知道实际的情况......我假设你的目标实际上是或者通过遍历他们或别的东西来获取动态添加的项目...

Without knowing the actual scenario... I am assuming your goal is actually to get the dynamically added items either by iterating over them or something else...

任何动态补充说,是在使用JavaScript / jQuery的客户端做的DOM元素,将不会自动反映到服务器端。您需要将它们序列化以不同的方式和回传过程中把它们放回到服务器端。你可以做到这一点的方法之一是通过序列化选择元素的所有选项中的一个隐藏的输入。如果你想使你更容易访问,你可以标记隐藏的输入为RUNAT =服务器,否则使用的Request.Form [......隐藏输入名称属性在这里......不是ID ......]来获得值OUT。当你得到它,你可以做你想做的任何值

Any dynamically added DOM element that is done on the client side using JavaScript / jQuery, will not be reflected automatically to the server side. You will need to serialize them in a different way and push them back to the server side during postback. One way you can do this is by serializing all the Options of the Select element in a hidden input. You can mark the hidden input as runat=server if you wish to make it easier for you to access, otherwise use Request.Form["...hidden input NAME attribute here... NOT ID..."] to get the value out. After you get it, you can do whatever you want with the values.

我想你的隐藏输入应该有像一些值:1:第一个值,2:第二个值3:...。只是做一些字符串操作给他们分裂和遍历他们。

I imagine your hidden input should have some value like: "1:First Value,2:Second Value,3:...". Just do some string manipulation to split them up and iterate over them.

这篇关于问题得到通过的jQuery在code后面添加列表框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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