Copy codeThe Code is as follows:
// Dynamically generate three controls
Protected void button#click (object sender, EventArgs e)
{
For (int I = 0; I <3; I ++)
{
TextBox t = new TextBox ();
T. ID = string. Format ("newTextBox {0}", I );
Panel1.Controls. Add (t );
}
ListControlsInPanel ();
}
Copy codeThe Code is as follows:
// Obtain the value of the dynamically generated control
Protected void Button3_Click (object sender, EventArgs e)
{
String str = "";
String [] ak = Request. Form. AllKeys;
For (int I = 0; I <Request. Form. Count; I ++)
{
// Only the values of the three dynamically generated controls are filtered out.
If (ak [I]. IndexOf ("new")>-1)
Str + = string. Format ("<li> {0} </li> <br>", Request. Form [I]);
}
Label1.Text = str;
}
// The ID of the newly generated control starts with "new". At the same time, ensure that no control ID on the page contains "new.