ここにコードを入力してください自動ポストバックでドロップダウンリストがアイテムを変更するときに動的テキストボックスを作成します。後で、送信ボタンがアクティブになったときにテキストボックスのテキストを取得したいと思います。しかし、ボタンがアクティブになると、テキストボックスは空白文字を返します。問題はページの寿命によるものに違いありません。これらの値を取得するには、どのような手法を使用する必要がありますか?
public class GuiOtherAuthors
{
public OtherAuthors[] tableOtherAuthors;
public Label[] lblName;
public TextBox[] txtName;
public Label[] lblSurname;
public TextBox[] txtSurname;
public Label[] lblInstitution;
public TextBox[] txtInstitution;
public Label[] lblCountry;
public TextBox[] txtCountry;
public Label[] lblEmail;
public TextBox[] txtEmail;
public PlaceHolder PlaceHolder1 = new PlaceHolder();
public Int32 NumberOfAutherOthos { set; get; }
public void InitializeControls()
{
tableOtherAuthors = new OtherAuthors[NumberOfAutherOthos];
lblName = new Label[NumberOfAutherOthos];
txtName = new TextBox[NumberOfAutherOthos];
lblSurname = new Label[NumberOfAutherOthos];
txtSurname = new TextBox[NumberOfAutherOthos];
lblInstitution = new Label[NumberOfAutherOthos];
txtInstitution = new TextBox[NumberOfAutherOthos];
lblCountry = new Label[NumberOfAutherOthos];
txtCountry = new TextBox[NumberOfAutherOthos];
lblEmail = new Label[NumberOfAutherOthos];
txtEmail = new TextBox[NumberOfAutherOthos];
for (int i = 0; i < NumberOfAutherOthos; i++)
{
lblName[i] = new Label();
lblName[i].Text = "Name:";
txtName[i] = new TextBox();
lblSurname[i] = new Label();
lblSurname[i].Text = "Surname:";
txtSurname[i] = new TextBox();
lblInstitution[i] = new Label();
lblInstitution[i].Text = "Institution:";
txtInstitution[i] = new TextBox();
lblCountry[i] = new Label();
lblCountry[i].Text = "Country:";
txtCountry[i] = new TextBox();
lblEmail[i] = new Label();
lblEmail[i].Text = "Email:";
txtEmail[i] = new TextBox();
}
}
public PlaceHolder makeGUI()
{
int i = 0;
int j = 1;
for (i = 0; i < NumberOfAutherOthos; i++)
{
Label authorInformation = new Label();
authorInformation.Text = "Information for Author " + j.ToString() + " :";
lblName[i].Text = "Name:";
lblSurname[i].Text = "Surname:";
lblInstitution[i].Text = "Institution:";
lblCountry[i].Text = "Country:";
lblEmail[i].Text = "Email:";
PlaceHolder1.Controls.Add(new LiteralControl("<table>"));
PlaceHolder1.Controls.Add(new LiteralControl("<span style=\"font-weight:bold;\" "));
PlaceHolder1.Controls.Add(authorInformation);
PlaceHolder1.Controls.Add(new LiteralControl("</span>"));
PlaceHolder1.Controls.Add(new LiteralControl("<tr><td>"));
PlaceHolder1.Controls.Add(lblName[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td><td>"));
PlaceHolder1.Controls.Add(txtName[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>"));
PlaceHolder1.Controls.Add(new LiteralControl("<tr><td>"));
PlaceHolder1.Controls.Add(lblSurname[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td><td>"));
PlaceHolder1.Controls.Add(txtSurname[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>"));
PlaceHolder1.Controls.Add(new LiteralControl("<tr><td>"));
PlaceHolder1.Controls.Add(lblInstitution[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td><td>"));
PlaceHolder1.Controls.Add(txtInstitution[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>"));
PlaceHolder1.Controls.Add(new LiteralControl("<tr><td>"));
PlaceHolder1.Controls.Add(lblCountry[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td><td>"));
PlaceHolder1.Controls.Add(txtCountry[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>"));
PlaceHolder1.Controls.Add(new LiteralControl("<tr><td>"));
PlaceHolder1.Controls.Add(lblEmail[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td><td>"));
PlaceHolder1.Controls.Add(txtEmail[i]);
PlaceHolder1.Controls.Add(new LiteralControl("</td></tr>"));
PlaceHolder1.Controls.Add(new LiteralControl("</table><br /> "));
j++;
}
return PlaceHolder1;
}
}
The code is in c#
Thanks
this is my page load:
private GuiOtherAuthors gui = new GuiOtherAuthors();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
numberOfOtherAuthors = NumberOfOtherAuthors();
if (!numberOfOtherAuthors.Equals(0))
{
gui.NumberOfAutherOthos = numberOfOtherAuthors;
gui.InitializeControls(); //Initialize the textboes
Panel1.Controls.Add(gui.makeGUI()); .. create my gui
setValueofOtherAuthors(numberOfOtherAuthors); //create object with value of textboxes
}
}
}