我正在用ASP.net制作应用程序。我有一个按钮,单击后会生成一些html,一些asp文本框和一个asp按钮(第二个按钮)。据我所知,这工作正常。现在我想要的是,当我单击第二个新创建的按钮时,我希望它创建一些html + asp.net文本框。这让我感到困惑,有没有更简单的方法?我似乎无法弄清楚,我为按钮2创建了onclick事件,但它尚不存在。非常感谢。认为以防万一,您想看一下代码可能会容易一些,以防万一。namespace ConnorMackayWebForm{public partial class InspectionCreate : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { //Set the initial amount of areas and hazards int areaCount = 0; int hazardCount = 0; //Check if the viewstate with the area count already exists if (ViewState["areaCount"] != null) { //Convert the view state back to an int areaCount = Convert.ToInt32(ViewState["areaCount"]); } else { ViewState["areaCount"] = areaCount; } //Check if the viewstate with the hazard count already exists if (ViewState["hazardCount"] != null) { //Convert the view state back to an int hazardCount = Convert.ToInt32(ViewState["hazardCount"]); } else { ViewState["hazardCount"] = hazardCount; } //Create the required number of areas for (int i = 1; i <= areaCount; i++) { createArea(i); } //Create the required number of hazards for (int i = 1; i <= hazardCount; i++) { createHazard(i); } } protected void btnCreateArea_Click(object sender, EventArgs e) { //Get the current number of areas int areaCount = Convert.ToInt32(ViewState["areaCount"]) + 1; //Create the area createArea(areaCount); //Set the new area into the viewstate ViewState["areaCount"] = areaCount; }
3 回答
繁花如伊
TA贡献2012条经验 获得超12个赞
再次感谢您的所有帮助。现在我唯一的问题是使所有这些都与viewstate一起使用。例如,我将命令参数传递给createbutton方法。现在,在要让其在重新加载时创建这些按钮的viewstate中,它希望传入相同的命令参数,因为它运行用于在重新加载时创建按钮的相同方法。现在有一种方法可以让我将这些按钮放置在重新加载的正确位置吗?万分感谢
- 3 回答
- 0 关注
- 350 浏览
添加回答
举报
0/150
提交
取消