hi,
good morning,
apply below,
--.aspx page
<asp:FileUpload ID="FileUploadCtrl" runat="server" Width="90%"/>
<asp:CustomValidator ID="CustomValidator2" runat="server" Display="Dynamic" ControlToValidate="FileUploadCtrl"
ErrorMessage="Please upload only pdf or docx file" SetFocusOnError="True" ValidateEmptyText="True"
ValidationGroup="ValGrp1" ClientValidationFunction="CheckValidFile"></asp:CustomValidator>
-- javascript
function CheckValidFile(source, arguments) {
var UploadDoc = document.getElementById('<%= FileUploadCtrl.ClientID %>');
var myfile = UploadDoc.value;
var format = new Array();
var Extension = myfile.substring(myfile.lastIndexOf('.') + 1).toLowerCase();
if (Extension == "pdf" || Extension == "docx") {
arguments.IsValid = true;
}
else {
if (UploadDoc.value == '')
alert('Please browse document to upload.');
else
alert('Please upload only pdf or docx file.');
arguments.IsValid = false;
}
}
used above customvalidator on your file upload control,and apply above javascript
hope this will help you.