I have One Linkbutton and Two Buttons in the page. I used below Javascript to disable buttons to avoid Double Clicks.
If the user clicked on Linkbutton, File will download and other buttons are disabled. But the Issue is Once File downloaded still other buttons are not enabled.
<script type="text/javascript">
function DisableButtons() {
var inputs = document.getElementsByTagName("INPUT");
for (var i in inputs) {
if (inputs[i].type == "button" || inputs[i].type == "submit") {
inputs[i].disabled = true;
}
}
}
window.onbeforeunload = DisableButtons;
</script>
protected void LbnFile_Click(object sender, EventArgs e)
{
if (con.State != ConnectionState.Open)
con.Close();
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("Select Filepath from TestTable where SRno=@SRNO ", con);
sda.SelectCommand.Parameters.AddWithValue("@SRNO", lblSRNO.Text.Trim());
DataSet ds = new DataSet();
sda.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
string filename1 = ds.Tables[0].Rows[0]["Filepath"].ToString();
if (filename1 != " ")
{
string Path = Server.MapPath("~/Files/Help/" + filename1);
if (File.Exists(Path))
{
Response.ClearContent();
Response.ContentType = "application/octect-stream";
Response.AppendHeader("content-disposition", "attachment; filename =" + filename1);
Response.TransmitFile(Server.MapPath("~/Files/Help/" + filename1));
Response.End();
LbnFile.Text = "Download";
}
else
{
LbnFile.Text = "No Files";
Response.Write("<script language='javascript'>window.alert('File not Exists!');</script>");
}
}
else
{
LbnFile.Text = "No Files";
Response.Write("<script language='javascript'>window.alert('No Files!');</script>");
}
}
}