0
我要添加动态控件.net - 如何动态添加控件?
像下面的图片我想做
我在努力做到这一点
如果我点击添加更多的经验按钮,我想要显示另一行
我试着用用户控制,但它不能正常工作。
下面的代码工作正常,但如果我添加控件,然后关闭浏览器页面,然后再次打开浏览器添加控件即将到来。
我认为问题是静态诠释我= 0;
static int i = 0;
protected void addnewtext_Click(object sender, EventArgs e)
{
i++;
for (int j = 0; j <= i; j++)
{
AddVisaControl ac = (AddVisaControl)Page.LoadControl("AddVisaControl.ascx");
placeHolder.Controls.Add(ac);
placeHolder.Controls.Add(new LiteralControl("<BR>"));
}
}
请提供你的想法?在此先感谢
IIRC静态变量将保留到服务器重新启动。相反,您需要使用另一种方法,即ViewState来存储该值。 – Gavin