Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
715
WebAsyncRefreshPanel Problem
posted

Dear All,
I'm using WebAsyncRefreshPanel in my aspx page, i try to download file from server using below code through button click, but i got the error
"Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack."

but i'm not get error without WebAsyncRefreshPanel. Please giva solution for this.

if (filename != "")

{
          string path = Server.MapPath(filename);
          System.IO.FileInfo file = new System.IO.FileInfo(path);
          if (file.Exists)
          {
                   Response.Clear();
                   Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                   Response.AddHeader("Content-Length", file.Length.ToString());
                   Response.ContentType = "application/octet-stream";
                   Response.WriteFile(file.FullName);
                   Response.End();
          }
          else
          {
                   Response.Write("This file does not exist.");
          }
}

Thanks in advance,
Regards,
Vasanth.

  • 45049
    posted

    Since you're taking over the Response object, I wouldn't expect WARP to be able to process this.  WARP (and UpdatePanel, for that matter) expect the response they get to be in a certain format.  Since you're sending something that isn't in that format, WARP doesn't know what to do with it.

    This is the same reason that Response.Redirect() doesn't work during an AJAX callback from the WARP.

    My suggestion:  Whatever event you have that calls this server-side code, you should not try to process through the WARP, either by moving the affected control outside the WARP or by adding that control's ClientID to the WARP's TriggerPostBackIDs property.