aspx Tutorial

NET Articles,jQuery demo, with jQuery, online tutorial,Jquery, SilverLight, Javascript,,JSON, MVC,.NET Articles,demo, Web Services,
Advertise Here


Get our toolbar!


Posted by Aamir Hasan   on Friday, November 19, 2010 Total Views:  

In this example, i will show you how to allow only specific file type ('jpeg', 'jpg', 'png', 'gif', 'bmp') to upload in using jQuery. Let’s start.

First, i have included Microsoft CDN jQuery reference file under the head section of Default.aspx page. I have created a function which will simply get a full file path then split it with dot(.), and i have used pop() method to get last element of split string.

Here’s an example.

<html xmlns="">

<head id="Head1" runat="server">

   <title>Restrict File Upload using jQuery in File Upload Control</title>

   <style type="text/css">

       html, body


           font-family: Verdana;

           font-weight: 10px;




           color: Red;



   <script src="" type="text/javascript"></script>

   <script language="javascript" type="text/javascript">

       $(document).ready(function () {

           var AllowedExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];

           $("#<%=FileUpload1.ClientID %>").change(function () {

               if ($.inArray($(this).val().split('.').pop().toLowerCase(), AllowedExtension) == -1) {

                   $("#<%=msg.ClientID %>").text("Only \'jpeg\', \'jpg\', \'png\', \'gif\', \'bmp\' are allowed.");

               } else {

                   $("#<%=msg.ClientID %>").text("");







   <form id="form1" runat="server">


       <h2>Restrict File Upload using jQuery in File Upload Control</h2>

       <asp:FileUpload ID="FileUpload1" runat="server" />

       <asp:Label ID="msg" runat="server" Text="" CssClass="alert"></asp:Label>



   <a href="">.NET Articles</a><br />

   Author:Aamir Hasan







File Upload Control .zip (1.18 kb)

See live demo

Protected by Copyscape Online Plagiarism Tool

Add comment

  Country flag

  • Comment
  • Preview

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5