I created an interface to pull data, there are a few simple steps.
Users select their desired data from drop boxes, they click a “Check Available” button, and if there are records available, a “Send Request” button shows.
After clicking the send request button, SQL tables are sent to an excel file, the file is slightly massaged with vba, then the user is emailed from C# with a link to this excel file.
The issue I’m facing is that the users get impatient after one or two seconds and start mashing the “send Request” button over and over again. This impatience crashes the application.
How could I make the page behave so that after clicking “Send Request”, the page is refreshed but the process is still carried out over the server and the email is still sent from C#.
public void SendRequest_Click(object sender, EventArgs e)
{
//Insert amazing line of code that refreshes the web form but does everything beyond this line
SendRequest.Visible = false;
//Creating a new class
QueryMule mule = new QueryMule();
Label11.Visible = true;
string myfilename = Label3.Text;
string splitusernum = Label4.Text;
string dtablenum = Label4.Text;
string exportnum = Label4.Text;
//Export all export tables to mercuryexport excel file
mule.SQLExport(18, splitusernum, exportnum);
//Creating a new excel application to open the mercury template and run its macro
ExcelApp.Application appExl;
ExcelApp.Workbook workbook;
ExcelApp.Worksheet newSheet;
ExcelApp.Range Range;
appExl = new ExcelApp.Application();
RegionName.SelectedItem.Value + timestampeddone + ".xlsm";
workbook = appExl.Workbooks.Open(@"filepath", Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
appExl.Visible = true;
appExl.DisplayAlerts = true;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add '''REMOVED EMAIL ADDRESS
message.Subject = "Delivery System";
message.From '''REMOVED EMAIL ADDRESS
message.Body = "filepath" + myfilename;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("mailhost");
smtp.Send(message);
Label4.Text = "Email Sent";
mule.DropTable(dtablenum);
mule.DropTable1(dtablenum);
mule.DropTable2(dtablenum);
mule.DropExportTable(dtablenum);
}
You’d need to spin off a background worker thread to create the excel file. The request would then respond immediately with a friendly message indicating that they will be emailed the link when it is ready.