<asp:HiddenField ID="hfFlag" runat="server" Value="0" ClientIDMode="Static" />
<asp:FileUpload ID="fuImages1" onchange="ValidateFileUpload(this);" runat="server"
ClientIDMode="Static" Width="100%" />
function ValidateFileUpload(FileUploadPath) {
if (FileUploadPath.value == '' || FileUploadPath.value == null) {
FileUploadPath.focus();
document.getElementById('hfFlag').value = "0";
alert("Please upload an image");
return false;
}
else {
var Extension = FileUploadPath.value.substring(FileUploadPath.value.lastIndexOf('.') + 1).toLowerCase();
if (Extension == "gif" || Extension == "png" || Extension == "bmp" || Extension == "jpeg" || Extension == "jpg") {
document.getElementById('hfFlag').value = "1";
return true;
}
else {
alert("Only allows file types : GIF, PNG, JPG, JPEG and BMP");
document.getElementById('hfFlag').value = "0";
FileUploadPath.focus();
return false;
}
}
}
<asp:FileUpload ID="fuImages1" onchange="ValidateFileUpload(this);" runat="server"
ClientIDMode="Static" Width="100%" />
function ValidateFileUpload(FileUploadPath) {
if (FileUploadPath.value == '' || FileUploadPath.value == null) {
FileUploadPath.focus();
document.getElementById('hfFlag').value = "0";
alert("Please upload an image");
return false;
}
else {
var Extension = FileUploadPath.value.substring(FileUploadPath.value.lastIndexOf('.') + 1).toLowerCase();
if (Extension == "gif" || Extension == "png" || Extension == "bmp" || Extension == "jpeg" || Extension == "jpg") {
document.getElementById('hfFlag').value = "1";
return true;
}
else {
alert("Only allows file types : GIF, PNG, JPG, JPEG and BMP");
document.getElementById('hfFlag').value = "0";
FileUploadPath.focus();
return false;
}
}
}
No comments:
Post a Comment