Hello Guys,
I have a issue.i am a making gridview double clikable. doubleclick on row i am calling a function name selectrow(rowindex) and inside function i am calling a javascript __dopostback('selectrow',rowindex) function.on pageload i am taking the value of Request.Form["__EVENTTARGET"] and Request.Form["__EVENTTARGET"] and check if Request.Form["__EVENTTARGET"]&&Request.Form["__EVENTTARGET"] not null then take the index of gridview selected row and call a function to download file listed in colum.till here fine.but after clicking on any button same vale of Request.Form["__EVENTTARGET"]&&Request.Form["__EVENTTARGET"] comes and downloadin start again.if button is not inside updatepannel if button is inside updatepannel javascript runtime error comes.
this is my code to function download
System.IO.FileInfo FileName = new System.IO.FileInfo(_Filename);
if (FileName.Exists)
{
FileStream myFile = new FileStream(_Filename, FileMode.Open,FileAccess.Read,FileShare.Write);
BinaryReader _BinaryReader = new BinaryReader(myFile);
long startBytes = 0;
string lastUpdateTiemStamp = File.GetLastWriteTimeUtc(_Filename).ToString("r");
string _EncodedData = HttpUtility.UrlEncode(_Filename, Encoding.UTF8) + lastUpdateTiemStamp;
Response.Clear();
Response.Buffer = false;
Response.AddHeader("Accept-Ranges", "bytes");
Response.AppendHeader("ETag", "\"" + _EncodedData + "\"");
Response.AppendHeader("Last-Modified", lastUpdateTiemStamp);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName.Name);
Response.AddHeader("Content-Length", (FileName.Length - startBytes).ToString());
Response.AddHeader("Connection", "Keep-Alive");
Response.ContentEncoding = Encoding.UTF8;
_BinaryReader.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int)Math.Ceiling((FileName.Length - startBytes + 0.0) / 1024);
int i=0;
try
{
for (i = 0; i < maxCount && Response.IsClientConnected; i++)
{
Response.BinaryWrite(_BinaryReader.ReadBytes(1024));
Response.Flush();
if (i == maxCount - 1)
{
_BinaryReader.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
_BinaryReader.Close();
File.Delete(outputFile);
}
if (i < maxCount)
{
MessageBox.Show("Error in downloading");
}
}
and on pageload this is my code
//////////////////
string source = Request.Form["__EVENTTARGET"];
string value = Request.Form["__EVENTTARGET"];
if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(value))
{
if (source.ToLower().Equals("selectrow"))
{
int SelectedRow = int.Parse(value);
string text = path + "\\" + GridView1.Rows[SelectedRow].Cells[0].Text;
Download(text);