private void createIngredientControl() { int count = this.NumberOfControls; for (int i = 1; i <= count; i++) { InlistControl tx = (InlistControl)LoadControl("~/InlistControl.ascx"); tx.ID = "UserControlIn" + i.ToString(); tx.EnableViewState = true; IngConatainer.Controls.Add(tx); } }
protected void btnSave_Click(object sender, EventArgs e) { Session["buttonType"] = "submit"; int time; List <Ingridients> ingredients1 = new List <Ingridients>(); for (int i = 0; i <= this.NumberOfControls; i++) { string con = "UserControlIn" + i.ToString(); InlistControl tx = (InlistControl)IngConatainer.FindControl(con); ingredients1.Add(new Ingridients { name = tx.TxtName, Quantity = Convert.ToInt32(tx.TxInQuantity), measureUnit = tx.IngMeasure }); } if (txtCooktm.Text == "") { time = 0; } else { time = Convert.ToInt32(txtCooktm.Text); } Recipe _objRecipe = new Recipe(); _objRecipe.name = txtName.Text; _objRecipe.submittedBy = txtSubmittedby.Text; _objRecipe.category = txtCategory.Text; _objRecipe.servings = Convert.ToInt32(txtServings.Text); _objRecipe.time = time; _objRecipe.description = txtDescription.Text; _objRecipe.ingredients = ingredients1; int error = _objrepositary.insertRecipe(_objRecipe); if (error == 0) { Status.Text = "Recipe added sucessfully"; } else { Status.Text = "Error ocurred"; } this.NumberOfControls = 0; }