【发布时间】:2018-04-23 06:11:31
【问题描述】:
我创建了一些动态控件,例如:TextBox。
这些是在ModalPopupExtender 中创建的,并且是在 ButtonClick 之后创建的。
protected void AddGroupBTN_Click(object sender, EventArgs e)
{
GroupMPE.Show();//GroupMPE is a ModalPopupExtender
ScheduleIdHF.Value = 1; //ScheduleIdHF is a HiddenField declared in the .aspx page
CreateControls(ScheduleIdHF.Value);
...
}
private void CreateControls(string ScheduleId)
{
TableRow TR = new TableRow();
TR.ID = "tableRow1";
TableCell TC = new TableCell();
TC.ID = "tableCell1;
TextBox textBox = new TextBox();
textBox.ID = "textBox1";
TC.Controls.Add(textBox);
TR.Cells.Add(TC);
ExampleTable1.Rows.Add(TR);//ExampleTable1 is declared in the .aspx page
}
然后,当单击另一个按钮时,我想像这样在Page_PreInit 上重新创建这些控件。
protected void Page_PreInit(object sender, EventArgs e)
{
if(IsPostBack)
{
if (!string.IsNullOrEmpty(ScheduleIdHF.Value))
{
CreateControls(ScheduleIdHF.Value);
...
但是,我希望对 CreateControls 的方法调用以HiddenField ScheduleIdHF 的值为条件并使用它。问题是 HiddenField 为 null 并且不是在 Page_PreInit 事件之后创建的。有没有人有任何解决方案来解决这个难题?因为我想在回发后得到TextBox的文字。
【问题讨论】:
-
我不认为这是可能的。请参阅文档:msdn.microsoft.com/en-us/library/ms178472.aspx
-
刚刚发布了一个答案。这很简单。
标签: c# asp.net dynamic textbox