取得动态创建的TextBox的值
在btnNext1_Click事件里创建了几个TextBox 控件,我想在btnNext2_Click取到这几个TextBox 的值 该怎么写?高人指点
protected void btnNext1_Click(object sender, EventArgs e)
{
for (int i = 0; i < int.Parse(txtcount.Text); i++)
{
TextBox txt = new TextBox();
txt.ID = "txt " + i.ToString();
txt.Style.Add( "width ", "280px ");
Literal htmInfo = new Literal();
htmInfo.Text = "内容 " + Convert.ToString(i + 1) + ": ";
Literal htm = new Literal();
htm.Text = " <br> ";
PlaceHolder1.Controls.Add(htmInfo);
PlaceHolder1.Controls.Add(txt);
PlaceHolder1.Controls.Add(htm);
}
}
protected void btnNext2_Click(object sender, EventArgs e)
{
}
------解决方案--------------------foreach (System.Web.UI.Control control in this.Controls[1].Controls)
{
colName=control.ClientID;
//检测判断
if (colName.IndexOf(preId)!=-1)
{
colName=colName.Replace(preId, " ");
//都变成小写
colName = colName.ToLower();
//colName=colName.Replace( "_ ", " ");
controlType=control.GetType().ToString();
//获取列的相关信息
foreach(DataRow row in dsCol.Tables[0].Rows)
{
if (row[ "colname "].ToString()==colName)
{
colNull=row[ "colnull "].ToString();
colType=row[ "coltype "].ToString();
colNote=row[ "colnote "].ToString();
}
}
//获取控件数值
switch(controlType)
{
case "System.Web.UI.WebControls.TextBox ":
inputCol=(System.Web.UI.WebControls.TextBox)control;
dr[colName]=inputCol.Text;
break;
case "System.Web.UI.WebControls.DropDownList ":
inputDrop=(System.Web.UI.WebControls.DropDownList)control;
if (inputDrop.SelectedIndex> =0)
dr[colName]=inputDrop.SelectedItem.Value;
break;
case "FreeTextBoxControls.FreeTextBox ":
inputFreeTextBox=