我正在用ASP.net制作應(yīng)用程序。我有一個(gè)按鈕,單擊后會(huì)生成一些html,一些asp文本框和一個(gè)asp按鈕(第二個(gè)按鈕)。據(jù)我所知,這工作正?!,F(xiàn)在我想要的是,當(dāng)我單擊第二個(gè)新創(chuàng)建的按鈕時(shí),我希望它創(chuàng)建一些html + asp.net文本框。這讓我感到困惑,有沒有更簡(jiǎn)單的方法?我似乎無(wú)法弄清楚,我為按鈕2創(chuàng)建了onclick事件,但它尚不存在。非常感謝。認(rèn)為以防萬(wàn)一,您想看一下代碼可能會(huì)容易一些,以防萬(wàn)一。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; }
如何在動(dòng)態(tài)創(chuàng)建的ASP.net控件中動(dòng)態(tài)創(chuàng)建ASP.net控件
尚方寶劍之說(shuō)
2019-11-04 13:00:29