动态创建的文本框可见性 [英] Dynamic created textbox visibility
本文介绍了动态创建的文本框可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我曾经在'创建'链接按钮上动态创建2个文本框。但是如果我去(或点击)下一个静态控件,当那个动态创建的文本框及其值不可见时......为什么?
我想保留动态文本框及其在整个页面中的价值,或直到我点击提交按钮。
有人建议解决这个问题吗?请!!
谢谢......
Hi,
I used to create 2 text boxes dynamically on the 'create' link button. But if i go to (or Click)next static controls, when that dynamic created textbox and its value will not be visible...why?
I want to keep that dynamic textboxes and its value throughout the page or till i click on 'Submit' button.
Can anyone suggest to solve this issue? please!!
Thank you...
推荐答案
你的动态创建的控件将在回发中丢失。将控件保留在会话中。你没有指定你的代码。让我们试试下面的示例代码,让我知道
Your dynamically created controls will lost in post back. Keep the control in a session. Yor are not specified your code. Lets try below sample code and let me know
protected void btnAddField_click( Object sender, EventArgs e ) {
int FieldCount = 0;
if (ViewState["FieldCount"] != null)
{
FieldCount = (int)ViewState["FieldCount"];
}
Table tbl = new Table();
if (Session["DynamicTable"] != null)
{
tbl = (Table)Session["DynamicTable"];
}
CheckBox chkNewField = new CheckBox();
chkNewField.ID = "chkNewField" + FieldCount.ToString();
chkNewField.Checked = true;
Label LblNewLabel = new Label();
LblNewLabel.ID = "lblNewLabel" + FieldCount.ToString();
LblNewLabel.Text = "New Lable";
TextBox TxtNewLabel = new TextBox();
TxtNewLabel.ID = "TxtNewLabel" + FieldCount.ToString();
Label LblNewValue = new Label();
LblNewValue.ID = "lblNewValue" + FieldCount.ToString();
LblNewValue.Text = "New Value";
TextBox TxtNewValue = new TextBox();
TxtNewValue.ID = "TxtNewValue" + FieldCount.ToString();
TableRow tRow = new TableRow();
TableCell tCell1 = new TableCell();
TableCell tCell2 = new TableCell();
tCell2.Attributes.Add("class", "medium");
TableCell tCell3 = new TableCell();
tCell3.Attributes.Add("class", "medium");
TableCell tCell4 = new TableCell();
TableCell tCell5 = new TableCell();
tCell5.Attributes.Add("class", "medium");
TableCell tCell6 = new TableCell();
tCell6.Attributes.Add("class", "medium");
tCell1.Controls.Add(chkNewField);
tCell2.Controls.Add(LblNewLabel);
tCell3.Controls.Add(TxtNewLabel);
tCell4.Controls.Add(new LiteralControl(""));
tCell5.Controls.Add(LblNewValue);
tCell6.Controls.Add(TxtNewValue);
tRow.Cells.Add(tCell1);
tRow.Cells.Add(tCell2);
tRow.Cells.Add(tCell3);
tRow.Cells.Add(tCell4);
tRow.Cells.Add(tCell5);
tRow.Cells.Add(tCell6);
tbl.Rows.Add(tRow);
placeHolderTable.Controls.Remove(tbl);
placeHolderTable.Controls.Add(tbl);
Session["DynamicTable"] = tbl;
FieldCount++;
ViewState["FieldCount"] = FieldCount;
}
这篇关于动态创建的文本框可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文