1

I am using one asp.net application where i used master page and content page. In one of the content page i am loading one grid which contains more data, And in master page i used update panel to show progress bar image with cancel button. Now when i am loading the grid on content page then progress bar is showing with cancel button. For clearing progress i have written loader image to hide on cancel click button in javascript which is working fine.

But my process is still running How do i cancel this process on click on cancel button. Below is the method which triggered when click master page button.

private void ViewReports(string someFilterCondition)
{
   //Business logic to get data from db.
}

When this method called in business logic taking more time. When click on cancel button it hides the loading image but user don't know whether the process is cancelled or not and after sometime when he got the loaded gridview then knows that process was still running. How do i cancel the current process?

V.Prasad
  • 131
  • 4
  • 19
  • Business logic taking more time - It seems sql query taking more time to give the result rite ? – Kavin Aug 03 '17 at 08:03
  • Yes Kavin, That's why i need here when click on cancel button process should kill for it. – V.Prasad Aug 03 '17 at 08:05
  • see this https://stackoverflow.com/questions/4779679/stop-sql-query-execution-from-net-code. hope it helps you. – Kavin Aug 03 '17 at 08:11
  • This is fine but i want it to be done on click on cancel button which closes the loading image in client side from there i have to do this. I tried to use ajax call from there but it is not working. Please help me if you have some solution regarding this. – V.Prasad Aug 03 '17 at 08:39
  • declare the command variable as global in that page. add the command.cancel(); in one function and call that function when click the cancel button using ajax. – Kavin Aug 03 '17 at 12:41
  • Did you fixed this? – Kavin Aug 03 '17 at 14:02

1 Answers1

1

Declare the static sql command variable as global in that page (only command variable). Then write one web method and cancel the command in it. Then Call that web method using AJAX when click the cancel button.

//Add the namespace on top of the page

using System.Web.Services;

//declare this variable globally in that page

 static SqlCommand command = new SqlCommand();

//c#

[WebMethod]
public static string CancelProcess()
{
   try
   {
       command.Cancel();
       return "true";
   }
   catch (Exception ex)
   {
       return ex.Message.ToString();
   }
}

//.aspx

<asp:Button ID="BtnCancel" runat="server" Text="Cancel" OnClientClick="BtnCancel_ClientClick(); return false;" />

//JS

function BtnCancel_ClientClick() {
    $.ajax({
        type: "POST",
        url: "HomePage.aspx/CancelProcess",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
        },
        failure: function (response) {
            //  add error handling code here                   
        }
    });
}

Hope it helps you..

Kavin
  • 303
  • 2
  • 14
  • Hi Cavin, Currently i am using another BA class where i have method for calling stored procedure. This method is calling from asp.net page. Now i don't have idea how do i send this command to that method which is already running. I have checked with ajax call then got to know that one process already running for loading data until that is not end this ajax call process is not starting only. – V.Prasad Aug 03 '17 at 14:52
  • I can help this much without your code, without ur code i can't do anything.. post your code and tell me where u stucking.. BTW, What is BA ? – Kavin Aug 03 '17 at 15:30
  • BA means i have other class library where business logic is defined like to execute procedure and return data. I have one simple question if one process is already running we can't send another process until the first is not completing. If that is the case then how do i cancel the specific command? – V.Prasad Aug 04 '17 at 07:24
  • yes it makes sense, but you can use the thread or assync operations to do multiple process in parallel. I have experience in threading with console application but not experienced in threading with asp.net web applications. Threading or assync is possible in asp.net web application, so please do research about it and share your results here. – Kavin Aug 04 '17 at 10:29