2

My problem looks like this. I have a grid with documents (Id's). Now when somebody clicks at a row I would like to allow him to download or show that document. But to make it esier let's say that I would do this on a button click. I tried two approaches but none of them worked form me.

  1. I tried to response.binarywrite on the button click:

            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.ContentType = "application/postscript mime";
            Response.AddHeader("content-disposition", "attachment; filename=test.ps"); 
            Response.AddHeader("content-length", _excuteGetDocumentResult.Length.ToString());
            Response.ContentEncoding = new System.Text.UTF8Encoding();
            Response.BinaryWrite(_excuteGetDocumentResult);
    

But nothing happens and when I try to modify this code I usually get some javascript errors saying sommething about changing the response...

The socond approach was opening new window and on page load adding the code above.

<asp:Button Text="ShowResult" OnClientClick="radopen('ShowResult.aspx','ShowDocumentDialog'); return false;"
        runat="server" />

The socond approach works but my opened window still exists after saving or canceling the explorer saving file dialog window. I tried to add some javascript to close it but it only works where there is no response.binarywrite on the load page...

Any ideas how I can achive what I want?

shin
  • 666
  • 2
  • 9
  • 25

1 Answers1

0

In method 1.

try Response.End(); after Response.BinaryWrite(_excuteGetDocumentResult);

ajay_whiz
  • 17,573
  • 4
  • 36
  • 44
  • I'm getting js error Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near 'II*'. – shin Apr 11 '11 at 12:21
  • 1
    Is this grid inside update panel? if yes, first try removing the update panel, you can't do such thing inside update panel (Ajax) – ajay_whiz Apr 11 '11 at 12:35
  • This is a Telerik radgrid but to make it simplier I'm doing it in the button click event but it still fails :/ that's why I thought about opening some extra window with only this response but the client would have to close it manually... – shin Apr 11 '11 at 12:46
  • @ajaz_whiz you're right...I have a master page in which the content place holder is wrapped with telerik:RadAjaxPanel and when I commented it out the 1 solution works...gues I will have to make it like that... – shin Apr 11 '11 at 12:57
  • @shin you can also try the second method. Do write `Response.End();` at the end, this should close the browser window. – ajay_whiz Apr 11 '11 at 15:14
  • @ajay_whiz unfortunately this throws the js exception. Mayby it's because it's a radwindow or sommething...nevertheless I will stick with the solution without the radajaxpanel :D Thanks – shin Apr 12 '11 at 09:31
  • Is there any way to achive some kind of ajax update to show user that the file is loading in any way? On the server sometimes the file is generating for few minutes and the site is without any loding panel and it looks horrible :/ any ideas? – shin Apr 18 '11 at 13:30
  • @shin for this you can have polling mechanism. you can call (Ajax) to a service which sends you a status whether the file is available for download – ajay_whiz Apr 18 '11 at 18:49