0

I have a user control on an ASP.Net page (that is using Master Pages) inside an UpdatePanel. This control has several functions, including buttons. The control works fine, except for one link where I'm trying to send a file to the client when they click on it.

The control is instantiated with an object which is used for display, action, and optionally serialized for transmitting to the client. I've sent files before, even in this project, but not from a UserControl, and not behind a UpdatePanel. The browser is acting as if I'm not even clicking on the link even though I can step through the code and I know it is working.

Response.Clear()
Response.AppendHeader("content-disposition", "attachment; filename=assignment.ics")
Response.ContentType = "text/xml"

'serialization code goes here

Response.Write(seralizedObject)
Response.Flush()
Response.End()

I've tried Response.Close instead. I've tried using Response.OutputStream.Write as well. Nothing seems to be working. Is what I'm trying to do even possible? Or do I need to devise some way to redirect to another page that will then send the file?

UPDATE: In view of the answer received, I've changed my implementation to point to another URL (an ashx file) to actually send the file. It works, but it isn't ideal. I'm still open to other suggestions on this one.

If an UpdatePanel doesn't work, I'd still like to 'internally' send the object to another file (like an ashx file) that could then send the file. Right now I'm using the URL querystring to send enough information to rebuild the object in my ashx file. Needless to say, that isn't a very pretty solution.

cjbarth
  • 4,189
  • 6
  • 43
  • 62

1 Answers1

0

You can't stream a file to the client with an update panel, for various reasons. File streaming doesn't work in this AJAX scenario. Try removing the UpdatePanel and to verify it works without, and then use conditional updating. See this for more information.

Community
  • 1
  • 1
Brian Mains
  • 50,520
  • 35
  • 148
  • 257