The following code from (http://www.aspsnippets.com/Articles/File-type-and-extension-validation-in-ASP.Net-AsyncFileUpload-Control-using-JavaScript.aspx)
<script type="text/javascript">
var errorMessage;
window.onload = function () {
try {
errorMessage = $get('<%=dvRequest.FindControl("lblMessage").ClientID %>').innerHTML;
$get('<%=dvRequest.FindControl("lblMessage").ClientID %>').innerHTML = "";
AjaxControlToolkit.AsyncFileUpload.prototype._onStart = function () {
var valid = this.raiseUploadStarted(new AjaxControlToolkit.AsyncFileUploadEventArgs(this._inputFile.value, null, null, null));
if (typeof valid == 'undefined') {
valid = true;
}
if (valid) {
valid = Validate(this._inputFile.value);
if (!valid) {
this._innerTB.value = "";
this._innerTB.style.backgroundColor = this._completeBackColor;
}
}
return valid;
}
}
catch (err) {
alert('Error: ' + err.Message);
}
}
var validFilesTypes = ["doc", "docx"];
function Validate(path) {
$get('<%=dvRequest.FindControl("lblMessage").ClientID %>').innerHTML = "";
var ext = path.substring(path.lastIndexOf(".") + 1, path.length).toLowerCase();
var isValidFile = false;
for (var i = 0; i < validFilesTypes.length; i++) {
if (ext == validFilesTypes[i]) {
isValidFile = true;
break;
}
}
if (!isValidFile) {
$get('<%=dvRequest.FindControl("lblMessage").ClientID %>').innerHTML = errorMessage;
}
return isValidFile;
}
</script>
I'm having the AsyncFileUpload control inside a detailsview on a usercontrol.
The usercontrol have the code
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
in the top
My problem is that the AjaxControlToolkit.AsyncFileUpload.prototype._onStart
method is giving me the error 'undefined'.
What can I do to avoid that?