-1

Here is my code.

protected void Send(object sender, ImageClickEventArgs e)
    {
        try
        {

            ObjCancellationTokenSource = new CancellationTokenSource();
            CancellationToken token = ObjCancellationTokenSource.Token;
            var ObjTask = Task<string>.Factory.StartNew(() =>
               {
                  while (!token.IsCancellationRequested)
                   {
                      for(i=0;i<n;i++)
                       { 
                         ----------some operation------ 
                       }
                     Response.Write("<script>alert('Completed.');</script>"); // not firing
                     Response.Redirect("Home.aspx", false);// raising error or not firing
                  }
               }, token);

        catch (Exception ex)
        {

        }
    }

So, here is my question is...

once the loop is finished inside the task I'm trying to show alert through Response.Write and after I need to redirect my page to another page through Response.Redirect...

but both or not working...

how can I achieve it??

if I do both Response.Redirect and Response.Write without using task operation.. its working fine.

I googled this .. but in all sites, all are using Console.Write method to show some alert. I don't want that.. I need to show real javascript alert and redirect the page ....

pls don't give any web reference.. give some code...

thanks all.

Keyur Ramoliya
  • 1,900
  • 2
  • 16
  • 17
saravanan049
  • 60
  • 10
  • why do you have Response.Redirect in a loop? how many times do you want to redirect? – Hooman Bahreini Jun 30 '18 at 03:16
  • @Hooman .. above is not actual code.. my question here ..is it possible to use responce.redirect and responce.write inside the task loop.. i need to redirect the control to another page once task or inside loop is finished.. – saravanan049 Jun 30 '18 at 04:09
  • this might help: https://stackoverflow.com/questions/21036805/how-can-i-redirect-to-an-action-using-task-in-asp-net-mvc – Hooman Bahreini Jun 30 '18 at 06:03
  • @Hooman .. given link is useful.. but my web application developed using .net 4.0 .. "RedirectToAction" is not working in 4.0 ... any other way?? – saravanan049 Jul 01 '18 at 04:13

1 Answers1

0

please try this. Response.Write("alert('Completed.');"); replace this code ScriptManager.RegisterClientScriptBlock(this, GetType(), "SUCEESSFULL", "alert('Completed');", true); after Response.Redirect working this code...

mitul
  • 1
  • 3
  • i tried ScriptManager.RegisterClientScriptBlock also.. but no use.. not working.. totally the keyword "response" is not working inside of task operation.. – saravanan049 Jul 01 '18 at 04:07
  • if i use "HttpContext.Current.Response.Redirect("UserPage.aspx", true);".. NullReferenceException was unhandle by user code ..error is raising.. – saravanan049 Jul 01 '18 at 06:02
  • Your Use any Update Panel Or Script Managaer?? – mitul Jul 02 '18 at 04:49
  • yes.. im using..the code given above is wirtten in imagebutton click event .. so by using update panel, im running .gif image until the task loop complete.. – saravanan049 Jul 02 '18 at 05:30
  • Remove Update Panel after try this code.....may be working this code...ScriptManager.RegisterClientScriptBlock(this, GetType(), "SUCEESSFULL", "alert('Completed');", true); – mitul Jul 02 '18 at 06:40