Hello All,
I have a dropdown in my aspx page from which I am downloading data.
From dropdown I will choose the file format and data will be downloaded in that particular format
Here is my drop-down.
<asp:DropDownList ID="ddlExportRprts" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlExportRprts_SelectedIndexChanged">
<asp:ListItem Text="Select" Value="0" Selected="True"></asp:ListItem>
<asp:ListItem Text="Excel" Value="1"></asp:ListItem>
<asp:ListItem Text="CSV" Value="2"></asp:ListItem>
</asp:DropDownList>
and here is the back-end method of the dropdown.
protected void ddlExportRprts_SelectedIndexChanged(object sender, EventArgs e)
{
string strFileName="Test";
string strDataFilePath = Server.MapPath("./AttachedFiles/") + "\\" + strFileName + ".xls";
DownLoadFile(strDataFilePath, strFileName);
}
private void DownLoadFile(string strFilePath, string strFileName)
{
if (System.IO.File.Exists(strFilePath))
{
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename =" + strFileName + ".xls");
Response.TransmitFile(strFilePath);
Response.End();
}
}
when ever I am selecting any option from drop down file is getting downloaded in selected format..no issues with that.
but after file is getting download and then I m clicking on any server side control like button, link button, check-box, radio-button any other drop down, this method
"ddlExportRprts_SelectedIndexChanged()" is being called where as these controls has there on click events.
I am confuse why these method is being fired when I m not calling it.
I am stuck in this problem from long time, I hope some1 out there knew how to solve it..
cheers in advance..
: )