protected void ButtonAddAlgorithm_Click(object sender, EventArgs e) { WebUserControlAlgorithms a = (WebUserControlAlgorithms)LoadControl("~/WebUserControlAlgorithms.ascx"); a.ID = PlaceHolderAlgorithms.Controls.Count.ToString() + "_Algorithm"; PlaceHolderAlgorithms.Controls.Add(a); List <WebUserControlAlgorithmsData> algorithmData = AlgorithmsData; // Get it out of the viewstate WebUserControlAlgorithmsData newData = new WebUserControlAlgorithmsData(); newData = a.Data; algorithmData.Add(newData); AlgorithmsData = algorithmData; }
public void Algorithm_UserControlButtonRemoveClicked(object sender, EventArgs e) { // TO DO cast.. WebUserControlAlgorithms toDel = (WebUserControlAlgorithms)sender; if (toDel != null) { // Find the index of the control int indexToDel = PlaceHolderAlgorithms.Controls.IndexOf(toDel); if (indexToDel >= 0) { List <WebUserControlAlgorithmsData> aData = AlgorithmsData; // Get it out of the viewstate aData.RemoveAt(indexToDel); AlgorithmsData = aData; LoadAlgorithmsControls(); LoadAlgorithmsEvents(); } } }
// Push the algorithms in the panelHolder again void LoadAlgorithmsControls() { List <WebUserControlAlgorithmsData> aData = AlgorithmsData; // Get it out of the viewstate if (aData != null) { PlaceHolderAlgorithms.Controls.Clear(); int countID = 0; foreach (WebUserControlAlgorithmsData a in aData) { WebUserControlAlgorithms algorithm = (WebUserControlAlgorithms)LoadControl("~/WebUserControlAlgorithms.ascx"); algorithm.LoadData(a); algorithm.ID = countID.ToString() + "_Algorithm"; ++countID; PlaceHolderAlgorithms.Controls.Add(algorithm); } } AlgorithmsData = aData; }
public void Algorithm_UserControlFieldChanged(object sender, EventArgs e) { WebUserControlAlgorithms m = (WebUserControlAlgorithms)sender; if (m != null) { // Find the control. int indexOfControl = PlaceHolderAlgorithms.Controls.IndexOf(m); if (indexOfControl >= 0) { List <WebUserControlAlgorithmsData> aData = AlgorithmsData; // Get it out of the viewstate if (aData.Count <= indexOfControl) { throw new ExecutionEngineException("Ooopps"); } aData[indexOfControl] = ((AlgorithmDataEventArgs)e).Data; AlgorithmsData = aData; } } }