本文介绍了如何在按钮单击时动态添加文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在按钮上添加文本框,无论何时单击按钮一次一个或两个...
i want to add textbox on button click one or two at a time on whatever times click on button ...
推荐答案
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["textBoxCount"] = 0;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int textBoxCount =(int) ViewState["textBoxCount"] ;
textBoxCount++;
for (var i = 0; i < textBoxCount; i++)
{
TextBox txt = new TextBox();
Literal lit = new Literal();
lit.Text = "";
PlaceHolder1.Controls.Add(txt);
PlaceHolder1.Controls.Add(lit);
}
ViewState["textBoxCount"] = textBoxCount;
}
这篇关于如何在按钮单击时动态添加文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!