-1

I'm currently working on a ASP .Net project. I have a search button, and after i press it, a connection to a WCF is made, and then data is retrieved. I want to add a Cancel button, and i want to cancel the search process when i press the Cancel button. The problem is I cant interrupt the postback, so no matter what I do, i cant stop the serach in the middle of the process. I have tried to refresh the page from javascript by calling the follwing: location.reload(true); . But it wont work. It will wait until the postback is finished and then reloads the page. I have also tried to abort the WCF connection after i press Cancel, but the result is the same. Can anyone help me please?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Arvind Ab
  • 25
  • 1
  • 8
  • Use Ajax to make the call to load the data. This will keep the main browser thread free to cancel it whenever. – NotMe Oct 30 '14 at 14:18
  • tnx for your help. Ill try it – Arvind Ab Oct 30 '14 at 14:19
  • @ChrisLively Ive tried to do as you tole. the problem is the if i use ajax, i will have to call a static method with ´[WebMethod]´ tag. this way i cannot access my page components which are non-static. – Arvind Ab Oct 31 '14 at 09:50
  • It sounds like you have three options. 1. Live with the idea of having a long running process which locks up the browser. 2. Fix the issues that cause your process to take so long. 3. Rearchitect the solution such that you don't have these dependencies. – NotMe Oct 31 '14 at 13:34
  • @ChrisLively tnx for your comment. We followed option 3. By using an .asmx service we give the user a time-window that they can cancel the process. We found out that, if postback is made there is no way to interrupt it than closing the browser. Should i publish an anser for the question her? And again thanks for your help. – Arvind Ab Nov 03 '14 at 09:53
  • Yes, publish the answer yourself. That way it can help others and close the question out. – NotMe Nov 03 '14 at 15:13
  • @ChrisLively thansk a lot for your help. It gave us good ideas to solve our problem. I posted an answer, but Im not able to close the question. I guess i need more points for that :). Tnx again – Arvind Ab Nov 03 '14 at 17:53

1 Answers1

0

Ok, we finally found the answer. First of all, we found out that if the postback is already made, there is nothing we could do to stop it. The only way time-window we could cancel the search is the time within which data are being fetched from the WCF service(Note that, client makes a request for data, and then the request is forwarded to a WCF service, and then the WCF service fetches data from a database). As soon as the request is returned from the WCF service there is nothing (As far as we know) that can be done to cancel the search process. We also tried creating new thread/task every time we request data. The problem was, when a new thread/task is created, connection to client side is lost, there for we couldnt update our component(such as gridview). As was suggested in the comments, we tried to make the data retrieving process via call from AJAX. The problem with AJAX call was we had to use a static method with [WebMethod] tag, and that made it impossible to use our non-static members. Finally, the solution was: 1- We moved our data request function to client side (javascript) 2- We used a .asmx service. That made it possible to call non-static functions from javascript This gave us a time-window, that we could use to cancel the serach process, starting from the time a user presses Search until data our back from the WCF service. finally, you can go to Call non-static method in server-side from client-side using JavsScript to see how you can use .asmx service.

Community
  • 1
  • 1
Arvind Ab
  • 25
  • 1
  • 8