This is a migrated thread and some comments may be shown as answers.

How to begin download with a button in grid

4 Answers 226 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Silvio Silva Junior
Top achievements
Rank 2
Silvio Silva Junior asked on 10 May 2010, 06:27 PM
Hello guys.

I have a grid with a ImageButton in a template column. In the click event of this button, I have this code:

FileInfo file= new FileInfo("D:\\projetos\\GED\\content\\upload\\00001\\20100510104408625_aurora_boreal_noruega.JPG"); 
 
        Response.Clear();        
 
        Response.ContentType = "application/octet-stream"
 
        Response.AddHeader("Content-Disposition""attachment; filename=" + file + ""); 
 
        Response.AddHeader("Content-Length", file.Length.ToString()); 
 
        Response.Flush(); 
 
        Response.WriteFile(file.FullName); 

But, when I click this button, I have an error:

"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed"

My grid is inside an ajax panel, and I think it is the problem, because I put another button out of ajax panel, with the same code in click event, and it works fine.

What's the best option for this case?

Thanks in advance.

Regards.

4 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 11 May 2010, 09:15 PM
Hello Silvio,

You should cancel the AJAX request and perform a standard postback when downloading/exporting files. Sample code-snippet is shown below:
<script type="text/javascript">
   function onRequestStart(sender, args)
   {
       if (args.get_eventTarget().indexOf("DownloadButton") >= 0)
           args.set_enableAjax(false);
   }
</script>

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="onRequestStart">
   ....
   <asp:ImageButton ID="DownloadButton" runat="server" ....
   ....
</telerik:RadAjaxPanel>

Let me know if you need further assistance.

Best regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 12 May 2010, 06:07 PM
Thank you Daniel.

I tryed your suggestion and it works fine, but I have another (2 actually) problem.

I have a master page, and so, when I try to use the name of component, the javascript function can't get the control. My code is like this:

<script type="text/javascript">     
   function onRequestStart(sender, args)     
   {     
       if (args.get_eventTarget().indexOf("ctl00_ContentPlaceHolder1_Button1") >= 0)     
           args.set_enableAjax(false);     
   }     
</script>    
 

But, it not works! The indexOf properties always is -1, so, how can I get the control?

The other problem is:

The code above was a test, but, in my real scenario I have a grid with a ImageButton in a template column, and, I searched for the imagebutton name (in source code page) and I didn't found it.

Can you make a simple project to show how it can work?

Thank you.

Best regards.
0
Accepted
Daniel
Telerik team
answered on 12 May 2010, 09:40 PM
Hello Silvio,

I suggested that you use indexOf  in order to help you avoid using hardcoded client id's (such as ctl00_ContentPlaceHolder....).

Please try to modify your code this way:

<script type="text/javascript">    
   function onRequestStart(sender, args)    
   {    
       if (args.get_eventTarget().indexOf("Button1") >= 0)    
           args.set_enableAjax(false);    
   }    
</script>

As to the second question - just use the ID of the control - you don't have to supply the full client id here - that's why I use indexOf instead of the standard equal sign.

I will gladly provide a runnable demo for you if this suggestion doesn't help.

Regards,
Daniel
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Silvio Silva Junior
Top achievements
Rank 2
answered on 31 May 2010, 02:04 PM
Hello Daniel.

Your answer works fine for me, thanks a lot.

Regards.
Tags
Grid
Asked by
Silvio Silva Junior
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Silvio Silva Junior
Top achievements
Rank 2
Share this question
or