Hi,
I have Datalist inside update panel linkbutton is not downloading files.
Below is my code
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:Panel runat="server" ID="Panel1" ChildrenAsTriggers="false">
<div style="vertical-align: middle; min-height: 480px;" class="pre-scrollable">
<div>
<asp:DataList ID="dl_Options" runat="server" p Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" RepeatLayout="Table">
<ItemTemplate>
<div>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("ImagePath") %>'></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Eval("ImagePath") %>' CommandArgument='<%# Eval("Id")%>' OnClick="DownloadFile"></asp:LinkButton>
</div>
</ItemTemplate>
</asp:DataList>
</div>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
Protected Sub DownloadFile(ByVal sender As Object, ByVal e As EventArgs)
Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)
Dim fileName As String, contentType As String
Dim constr As String = ConfigurationManager.ConnectionStrings("RegistrationConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand()
cmd.CommandText = "select * from upload where Id=@Id"
cmd.Parameters.AddWithValue("@Id", id)
cmd.Connection = con
con.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
sdr.Read()
'bytes = DirectCast(sdr("ImagePath"), Byte())
'contentType = sdr("ContentType").ToString()
fileName = "D:\Documents\upload\" & sdr("ImagePath").ToString()
End Using
con.Close()
End Using
End Using
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.AppendHeader("Content-Disposition", Convert.ToString("attachment; filename=") & fileName)
Response.Flush()
Response.[End]()
End Sub
Event is fire but file is not downloading
Thanks
Basit.