动态创建的控件回发后丢失数据

编程入门 行业动态 更新时间:2024-10-27 06:19:35
本文介绍了动态创建的控件回发后丢失数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

其实,我创建1 文本框在页面加载,并补充说,文本框到面板。 现在,我有一个的LinkBut​​ton 如添加其他。

Actually, I am Creating 1 TextBox on Pageload and adding that TextBox to Panel. Now, I have a LinkButton like Add Another.

我进入了文本文本框,如果需要,我需要创建新的文本框,点击添加其他的LinkBut​​ton 。

I am entering Text in that TextBox and if needed I need to Create New TextBox,by clicking Add Another LinkButton.

其实,我能够得到计数并重新创建文本框。 但是,问题在于,在previously生成文本框我输入的文本丢失。

Actually, I am able to get the count and recreate the TextBoxes. But,the Problem is that, My Entered text in the Previously Generated Textboxes is Missing.

谁能,推荐我一个解决方案吗?

Can Anyone,Suggest me a solution for this?

protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { for (int i = 0; i < 5; i++) { TableRow row = new TableRow(); for (int j = 0; j < 5; j++) { TableCell cell = new TableCell(); TextBox tb = new TextBox(); tb.ID = "TextBoxRow_" + i + "Col_" + j; cell.Controls.Add(tb); row.Cells.Add(cell); } Table1.Rows.Add(row); } } } catch (Exception ex) { throw; } }

这是一个简单的code,同样code是写在 Button_Click 同时

This is a Sample Code, the same code is written in Button_Click Also

protected void ASPxButton1_Click(object sender, EventArgs e) { int k = Table1.Controls.Count; }

我得到一个计数= 0 在 Button_Click 。

推荐答案

所有您需要重新实例化/重新初始化动态控制每一次之前,或在页面加载事件回发过程中并添加此控制页/表格/占位符再发布的数据就会自动调用方法的LoadPostData由母公司控制被分配给控件。

All you need to re-instantiate / reinitialize dynamic controls before or within page load event each and every time during postback and add this control to page / forms / placeholders then posted data will automatically be assign to the control by calling LoadPostData method by the parent control.

检查本文以及如何编写$ C $下动态控制 - 的 如何保养动态控制的事件,回发在asp中数据 的

check the article and how to write code for dynamic control - How to maintain dynamic control events, data during postback in asp

更多推荐

动态创建的控件回发后丢失数据

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

发布评论

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

>www.elefans.com

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