New here and relatively new to development and very new to ASP.
I have created a WCF service with a method that ultimately inserts a record into a SQL table and calls an email send class.
On my ASP web form that consumes the service, I have a button that invokes one of the methods.
What I dont understand and wish to fix, the method all in takes around 10 seconds to complete (I need to get this down but thats for further down the line). I can keep clicking the button before the first click has had a chance to complete and in turn send the email. With each click, it queues up and before you know it you have 10 identical emails.
I want to disable the button until the method has returned.
I have spent all day trying to resolve this and have looked and multiple forums, coming up with nothing. So any help is appreciated. - I cant work out what I'm missing.
Service Method;
public class A : IA
{
public int Set_A(string a, int t, string d, string c, int f)
{
using (var dbAbs = new Entities())
{
if (a != "" && d != "" && c != "")
{
// Do stuff - add to entity etc.
if (tl != null)
{
try
{
SendMail(tl.TL_E, a, t, d, c, f);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
Retval = dbAbs.SaveChanges();
}
else
{
retval = -99;
}
return retval;
}
else return -1;
}
}
Code behind the button click on the web form;
protected void AddA_Click(object sender, EventArgs e)
{
AddA.Enabled = false;
AddA.Visible = false;
var absvc = new AService.AClient();
// setting up variables
int ret = absvc.Set_A(a, ab, d, c, f);
//error handling
AddA.Enabled = true;
AddA.Visible = true;
}
As you can see, I've tried to use .Enabled and .Visible but they never seem to work.
Any help is appreciate, I've ive not provided enough info just shout at me!
Cheers Liam