0

I currently have a button on my aspx, when it is clicked, it calls a method to download a jpeg file from a server. The Jpeg file is a chart created with Infragistic.

My current Download method is this:

 private void DownLoad(string pImagen)
    {

        Context.Response.ClearContent();
        Context.Response.Clear();
        Context.Response.ContentType = "application/jpeg";
        Context.Response.AddHeader("Content-Disposition", "attachment; filename =" + pImagen);
        Context.Response.Flush();
        Context.Response.TransmitFile(ConfigurationManager.AppSettings["UploadPath"] + pImagen);
        Context.Response.End();
    }

But after the method is executed, a JSruntime error pops up:

Microsoft JScript runtime error: System error: -1072896748.

The error is located in a file called "ig_shared.js" in this method:

this._doResponse = function(cb)
{
    var request = cb.request;
    if(!request || request.readyState != 4)
        return false;
    var txt = request.responseText, sep = this._sep, sepLen = this._sepLen;

When i debug, Visual Studio shows a message that says "The name 'Request' does not exist in the current context" in this code line:

var txt = request.responseText

Maybe I'm missing something, but i have no idea what could be wrong.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user3642846
  • 31
  • 1
  • 1
  • 3
  • I'm not sure if it's relevant, but why are you using `TransmitFile` instead of `WriteFile`? Also, you don't have a `Response.End()` on there. – BRW May 29 '14 at 17:56
  • I tried with `WriteFile` at first, but i read that it's better to use `TransmitFile` just to be sure that the files doesn't get corrupted. Also, i forgot to add the `Response.End()` when i pasted the code, it is already edited now. – user3642846 May 29 '14 at 18:06
  • Really? I've never read that before. I always use `WriteFile`, followed by `Flush`, followed by `End`. – BRW May 29 '14 at 18:07
  • "Request" does not exist in the current context, but "request" does. – Igor May 29 '14 at 18:08
  • The problem may be in the fact that you are returning the content of a jpeg file, but `_doResponse` seems to expect text. How is `DownLoad(string pImagen)` invoked? – Igor May 29 '14 at 18:14
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackoverflow.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders May 30 '14 at 19:46
  • Is the button inside of a WebAsyncRefreshPanel? If so, does moving the button out of the WebAsyncRefreshPanel resolve the issue? – alhalama Jun 03 '14 at 17:23

0 Answers0