protected void ButtonSavePredict_Click(object sender, EventArgs e) { int budgetTotal = 0; int budgetAttempt = 0; for (int month = 1; month <= 12; month++) { TextBox box = (TextBox)this.Master.FindControl("BodyContent").FindControl("TextPredictMonth" + month.ToString()); string boxText = box.Text; if (!Int32.TryParse(boxText, NumberStyles.Number, new CultureInfo("sv-SE"), out budgetAttempt)) { ScriptManager.RegisterStartupScript(this, Page.GetType(), "error", "alert('The prediction for \"" + Server.HtmlEncode(new DateTime(_year, month, 1).ToString("MMMM")) + "\" does not appear to be a valid number. Please correct this and try again.');", true); return; } budgetTotal += budgetAttempt; } // Verify that the budget is not overallocated double budgetCeiling = _account.GetBudget(_year); if (Math.Abs(budgetTotal) > Math.Abs(budgetCeiling)) { ScriptManager.RegisterStartupScript(this, Page.GetType(), "error", "alert('You are predicting an overallocation of the budget. Your budget is " + budgetCeiling.ToString("N0") + " and you are predicting a total of " + budgetTotal.ToString("N0") + ". Please correct this and try again.');", true); return; } // Finally, actually set the values as good and repopulate them for (int month = 1; month <= 12; month++) { TextBox box = (TextBox)this.Master.FindControl("BodyContent").FindControl("TextPredictMonth" + month.ToString()); string boxText = box.Text; Int64 newMonthly = Int64.Parse(boxText, NumberStyles.Number, new CultureInfo("sv-SE")); _account.SetBudgetMontly(_year, month, newMonthly * 100); } PopulateBudgetData(); }