看看这段代码:
static int i = 0;
protected void Page_Load(object sender, EventArgs e)
{
HtmlButton myButton;
if (!Page.IsPostBack)
{
myButton = new HtmlButton();
myButton.InnerText = "Button first load";
myButton.ID = i.ToString();
PlaceHolder1.Controls.Add(myButton);
i++;
}
else
{
myButton = new HtmlButton();
myButton.InnerText = "Button postback" + i.ToString();
myButton.ID = i.ToString();
PlaceHolder1.Controls.Add(myButton);
i++;
}
}
预期的:
first load: "Button first load"
first postback: first load + "Button postback1"
second postback: first postback + "Button postback2" ... and so on.
有:
"Button first load"
"Button postback1"
"Button postback2".
为什么?