I have a MessageBox
display when submitting a stream read file. However the box keeps coming up even after clicking okay. When I hold down the Enter key to fly through the boxes, only one field gets added from the file.
Heres my codebehind
if (FileTypeDDL.SelectedValue == "Calendar Dates" && fileName == "calendar_dates.txt")
{
//Check if full txt has already been uploaded
SEPTA_DS.CalendarDatesTBLDataTable GetCalendarDates = (SEPTA_DS.CalendarDatesTBLDataTable)cdta.GetDataByCategory(Convert.ToString(Session["Cat"]));
var category = Convert.ToString(CategoryDDL.SelectedItem);
var service_id = Convert.ToString(row["service_id"]);
var date = Convert.ToString(row["date"]);
var exception_type = Convert.ToString(row["exception_type"]);
if (GetCalendarDates.Rows.Count < 1)
{
int insertData = Convert.ToInt32(cdta.InsertCalendarDates(category, service_id, date, exception_type));
}
else
{
DialogResult result = MessageBox.Show("This will overwrite the current list. Are you sure you wish to continue?", "Important Message",
MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation);
if (result == DialogResult.Yes)
{
int updateData = Convert.ToInt32(cdta.UpdateCalendarDates(category, service_id, date, exception_type, Convert.ToInt32(GetCalendarDates.Rows[0]["CalendarID"])));
}
else
{
Response.Redirect("~/Import.aspx");
}
}
}
I just want the box to appear once and on 'Yes' insert the data. Why and how can I accomplish this.
EDIT: I just realized that this code is within a foreach
loop and that's why it's reoccurring. My new question; How do I only show this MessageBox
once?