How to get values from dynamically created elements using jquery in code behind

梦想与她 提交于 2019-12-11 08:08:29

问题


Hi and thanks for taking the time to asnwer my question.

I have the following problem. I have a form and a button which says "add new activities".

Whenever the button is clicked I add a new set of elements, namely 2 drop down menus + text area. How can I get the values of these newly created elements in code behind since I cannot know their ids up front?

If there is something unclear about my question, please let me know.

Thanks again!


回答1:


But you must be setting id's (more importantly - name attributes) of new elements using certain pattern. Use the same pattern in a loop in server-side code to get values from Request.Form. Provide a hidden input where you put the total count of items added for the server-side to know the upper bound of loop counter.




回答2:


You should set the ids when you create the elements if you plan to access them again So if you this is your text area:

var textarea = document.createElement('textarea');

You can set the id to like this:

textarea.id = "taId";


来源:https://stackoverflow.com/questions/13768563/how-to-get-values-from-dynamically-created-elements-using-jquery-in-code-behind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!