You need to create the controls int the Page_Init
event, not Page_Load
.
How to dynamically set location of the text boxes
質問
I am doing a project of university. I want to create textboxes at run time and set their location one after another. Can anybody help me in setting their size and pattern?
namespace DynamicControl
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int rowCount = 10;
//Create the textboxes
for (int i = 0; i < rowCount; i++)
{
TextBox TxtBoxMessage = new TextBox();
TxtBoxMessage.ID = "TextBoxMessage" + i.ToString();
//Add textboxes to the Panel.
Panel1.Controls.Add(TxtBoxMessage);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}
解決
所属していません StackOverflow