.NET动态生成textbox控件
本帖最后由 shengrl2007 于 2013-07-09 15:10:10 编辑
protected void drpFloor_SelectedIndexChanged(object sender, EventArgs e)
{
int drpFloor = int.Parse(this.drpFloor.SelectedValue);
DynamicTable1(drpFloor+1);//在页面动态添加textbox的函数。
TextBox TempTextBox;
TempTextBox = ((TextBox)Table2.FindControl("tb21"));
TempTextBox.Text = "1";
}
在dropdownlist事件中,可以找到tb21。但是在button事件中却找不到tb21。
protected void btnConfirm_Click(object sender, EventArgs e)
{
TextBox TempTextBox1;
TempTextBox1 = ((TextBox)Table2.FindControl("tb21"));//实例对象未初始化。
TempTextBox1.Text = "2";
}
觉得很是奇怪啊,求指导!
------解决方案--------------------/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
LogicFloor();
}
int floor;
if (!int.TryParse(this.drpFloor.SelectedValue, out floor)) {
floor = 0;
}
if (floor > 0) {
DynamicTable1(floor + 1);
DynamicTable2(floor + 1);
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpFloor_SelectedIndexChanged(object sender, EventArgs e) {