我无法获取动态生成的文本框的ID。因此,我无法得到他们的价值观。在下面发布我的代码。请帮忙 。
protected void txt_Freq_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int rem = Convert.ToInt16(ddl_freq.SelectedItem.Value.ToString());
Table tbl1 = new Table();
form1.Controls.Add(tbl1);
for (i = 1; i <= rem; i++)
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
TextBox tb = new TextBox();
tb.ID = "rem" + i.ToString();
Label lb = new Label();
CalendarExtender calex = new CalendarExtender();
calex.ID = "calexRem" + i.ToString();
calex.TargetControlID = "rem" + i.ToString();
DropDownList txt_Time_rem = new DropDownList();
txt_Time_rem.ID = "ddl" + i.ToString();
for (int hr = 0; hr <= 23; hr++)
{
for (int min = 0; min < 60; min += 15)
{
if (hr <= 9 && min == 0)
txt_Time_rem.Items.Add(new ListItem('0' + hr.ToString() + ':' + '0' + min.ToString()));
else if (hr <= 9 && min != 0)
txt_Time_rem.Items.Add(new ListItem('0' + hr.ToString() + ':' + min.ToString()));
else if (hr > 9 && min == 0)
txt_Time_rem.Items.Add(new ListItem(hr.ToString() + ':' + '0' + min.ToString()));
else
txt_Time_rem.Items.Add(new ListItem(hr.ToString() + ':' + min.ToString()));
}
}
txt_Time_rem.Items.Insert(0, new ListItem("Time"));
lb.Text = "Reminder " + i.ToString();
cell.Controls.Add(lb);
cell.Controls.Add(tb);
cell.Controls.Add(calex);
cell.Controls.Add(txt_Time_rem);
row.Cells.Add(cell);
tbl1.Rows.Add(row);
Response.Write(tb.ID);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void btntemp_Click(object sender, EventArgs e)
{
TextBox tb = new TextBox();
for(x=1;x<=Convert.ToInt16(ddl_freq.SelectedItem.Value.ToString());x++)
{
TextBox txtUserName = form1.FindControl("rem"+x.ToString()) as TextBox;
if (txtUserName != null)
{
Response.Write("ID found!");
}
else
{
Response.Write("Failed");
}
我尝试用Page.Master替换form1,因为我有一个母版页,但没有任何作用。它将打印&#34;失败&#34;。请帮助。