我正在用ASP.net制作應(yīng)用程序。我有一個按鈕,單擊后會生成一些html,一些asp文本框和一個asp按鈕(第二個按鈕)。據(jù)我所知,這工作正?!,F(xiàn)在我想要的是,當(dāng)我單擊第二個新創(chuàng)建的按鈕時,我希望它創(chuàng)建一些html + asp.net文本框。這讓我感到困惑,有沒有更簡單的方法?我似乎無法弄清楚,我為按鈕2創(chuàng)建了onclick事件,但它尚不存在。非常感謝。認(rè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; }
3 回答

繁花如伊
TA貢獻(xiàn)2012條經(jīng)驗(yàn) 獲得超12個贊
再次感謝您的所有幫助?,F(xiàn)在我唯一的問題是使所有這些都與viewstate一起使用。例如,我將命令參數(shù)傳遞給createbutton方法?,F(xiàn)在,在要讓其在重新加載時創(chuàng)建這些按鈕的viewstate中,它希望傳入相同的命令參數(shù),因?yàn)樗\(yùn)行用于在重新加載時創(chuàng)建按鈕的相同方法?,F(xiàn)在有一種方法可以讓我將這些按鈕放置在重新加載的正確位置嗎?萬分感謝
- 3 回答
- 0 關(guān)注
- 367 瀏覽
添加回答
舉報
0/150
提交
取消