如何重置ASP.NET c#页上动态创建的控件的值?
我在面板控件中添加了一系列按钮,需要将它们重置为其原始值,这在实用上可行吗如何重置ASP.NET c#页上动态创建的控件的值?,c#,asp.net,C#,Asp.net,我在面板控件中添加了一系列按钮,需要将它们重置为其原始值,这在实用上可行吗 protected void Page_Load(object sender, EventArgs e) { RenderTable(); } private void RenderTable() { Button[] board = new Button[9]; for(int i =0; i <board.Length; i++) { board[i] = ne
protected void Page_Load(object sender, EventArgs e)
{
RenderTable();
}
private void RenderTable()
{
Button[] board = new Button[9];
for(int i =0; i <board.Length; i++)
{
board[i] = new Button();
board[i].Text = " ";
board[i].Width= board[i].Height = 50;
board[i].Click += PlayerClick;
board[i].ID = "pos" + i;
Panel1.Controls.Add(board[i]);
}
}
受保护的无效页面加载(对象发送方,事件参数e)
{
可渲染();
}
私有void可渲染()
{
按钮[]板=新按钮[9];
对于(int i=0;i您还应该能够存储原始值的数组,并循环重新分配它们。panel.Controls.Clear()?您需要自己将这些值存储在会话、视图状态中,或者只需在post值中查找它们。您已经在使用自定义ID,因此如果使用表单post方法,请使用这些值