我正在用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;
}
繁花如伊
相关分类