动态将控件添加到ASPX页面

编程入门 行业动态 更新时间:2024-10-10 11:28:55
本文介绍了动态将控件添加到ASPX页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 我有一个aspx页面.最初它将具有以下控件. 5个标签,3个文本框,2个下拉框, 3个按钮. 我的按钮之一是"ADD". 单击``添加''按钮时要完成的功能是添加另一组相同的控件,即5个标签,3个文本框,2个具有不同ID的下拉框. 以前的控件应保留在页面中.有了它们,应动态添加相同的控件. 如果需要将以上控件添加超过20次,则用户可以按下"ADD"按钮20次以上 请帮助动态添加这些控件,以及如何处理它们并从这些新控件中检索值. 请不要介意我的英语不好. 谢谢.

Hello, I am having an aspx page. It initially will have the following controls. 5 lables, 3 text boxes, 2 dropdown boxes, 3 buttons. One of my button is ''ADD''. The function to be done on click of the ''ADD'' button is to add another set of same controls , i.e., 5 lables, 3 text boxes, 2 dropdown boxes with different IDs. The previous controls should remain in the page.With them , same controls should be added dynamically. User can press the ''ADD'' button more than 20 times if needed to add the above controls more than 20 times Kindly help with adding these controls dynamically and how to handle them and retrieve values from these new controls. Please dont mind my bad english. Thanks.

推荐答案

您可以随意添加它们.但是,除非您创建一种机制来使用隐藏的控件来跟踪它们,这些隐式控件包含告诉您如何重新创建它们的值,否则它们将不会在回发时还原.动态创建的控件没有viewstate.这基本上是一个坏主意.最好的方法是使所有动作都通过jquery使用AJAX进行,这样就无需回发,也无需重新创建控件. You can add them as often as you like. However, they will not be restored on a postback unless you create a mechanism to track them using a hidden control to contain values telling you how to recreate them. There is no viewstate for dynamically created controls. It''s basically a bad idea. The best way to do this is to make all your actions occur using AJAX with jquery, that way there''s no postback and no need to recreate the controls.

更多推荐

动态将控件添加到ASPX页面

本文发布于:2023-08-03 12:41:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287106.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   页面   动态   ASPX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!