We've got a rather old asp.net webforms site that uses an asp.net linkbutton to allow a user to download a file. We originally had this as a simple a href but we had to process a button click event on the server side in order to run some back end code. Everything works fine in chrome, however, in IE (we're running IE 11) whenever you click to download a file using this linkbutton you get the following client side error:
Error: The value of the property '__doPostBack' is null or undefined, not a Function object
Our backend code does not even get triggered so we know it isn't a server side error as the debugger doesn't even hit. We did some searching to see what could be causing this and most people mentioned you need to have .net 4.5 installed on the server. But we already have .net 4.5 installed and we've run into other posts with similiar issues that simply did not apply to us.
I am trying to help another team resolve this but we are not getting anywhere with this. The link button definition is as simple as:
<asp:LinkButton runat="server" ID="lbName2" Target="_blank" OnClick="DownloadFile_Click"></asp:LinkButton>
The OnClick
event is just some server side code but again we don't even hit the server side code, but if it helps here is the code:
protected void DownloadFile_Click(object sender, EventArgs e)
{
var fileName = lbName2.Text;
string newFileName;
var serverPath = HttpContext.Current.Server.MapPath(hdnParentDocumentAbsolutePath.Value);
//get starting point of version within file name
//for instance mydocument(v1.0).docx
int index = fileName.IndexOf("(v");
if (index > 0)
{
//found a version number, strip it out.
var name = fileName.Substring(0, index);
int index2 = fileName.IndexOf(").");
var extension = fileName.Substring(index2 + 2);
newFileName = name + "." + extension;
}
else
{
newFileName = fileName;
}
//download the file
FileInfo file = new FileInfo(serverPath + "\\" + fileName);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + newFileName);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
When we click the linkbutton we get the script error and then we get the This page can't be displayed
error in IE. It is supposed to simply download the file. Again this works fine in chrome and ff but not in IE11.