Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a gridview and a link button within the gridview along with an update panel.

But the Link button is for download the file that not downloading after using update panel.

Is there any code postback for link button within update panel

Also i got an Error for loading... A control with ID 'lnkDownload' could not be found

for the trigger in UpdatePanel 'UpdatePanel1'.

What I have tried:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
 <contenttemplate>
<div style="margin-left: 140px; margin-top: 90px">
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                    BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" 
                    CellPadding="4" AllowPaging="true" PageSize="50" 
                    OnRowCommand="GridView1_RowCommand" OnRowEditing="GridView1_RowEditing" 
                    OnRowCancelingEdit="GridView1_RowCancelingEdit" 
                    onrowdatabound="GridView1_RowDataBound1">
                    <columns>
                        <asp:TemplateField HeaderText="USER ID">
                            <itemtemplate>
                                <asp:Label ID="Label21" runat="server" Text='<%# Bind("userid") %>'>
                            
                        

<asp:TemplateField HeaderText="FILE DOWNLOAD">
                            <itemtemplate>
                                <asp:LinkButton ID="lnkDownload" ToolTip="Click here for download the file" runat="server" Text="Download File" CommandArgument='<%# Bind("FILEPATH") %>' CommandName="download" OnClick="lnkDownload_Click" ForeColor="Blue" Font-Underline="True">
                            
                        
<pre>
                    <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
                    <HeaderStyle BackColor="#008B8B" Font-Bold="True" ForeColor="#CCCCFF" />
                    <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
                    <RowStyle BackColor="White" ForeColor="#003399" />
                    <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                


 
    
                <triggers>
  <asp:AsyncPostBackTrigger ControlID="lnkDownload" EventName="lnkDownload_Click" />
Posted
Updated 27-Jul-17 2:46am
v3
Comments
F-ES Sitecore 27-Jul-17 6:52am    
The problem is more likely with the click event of the link button. If it is sending a file to download to the client that will work as a normal click as it is processed as part of a normal http request\response by the browser. When you put it in an updatepanel then it becomes an ajax request processed by javascript and you can't send a file to the client via javascript. Basically you should add PostBack trigger to the updatepanel so that the linkbutton click does not happen asynchronously.

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-getting-started/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers

1 solution

I would suggest forgoing the async postback altogether and downloading the file by opening a new window on a link with target="_blank" and the path to the file as the HREF.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900