动态创建的控件回发后丢失数据 [英] Dynamically Created Controls losing data after postback
问题描述
其实,我创建1 文本框
在页面加载
,并补充说,文本框
到面板
。
现在,我有一个的LinkButton
如添加其他
。
Actually, I am Creating 1 TextBox
on Pageload
and adding that TextBox
to Panel
.
Now, I have a LinkButton
like Add Another
.
我进入了文本文本框
,如果需要,我需要创建新的文本框
,点击添加其他的LinkButton
。
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.net中数据 的
check the article and how to write code for dynamic control - How to maintain dynamic control events, data during postback in asp.net
这篇关于动态创建的控件回发后丢失数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!