Click here to Skip to main content
12,401,173 members (37,323 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

22.8K views
3 bookmarked
Posted

Check File type at client side – jQuery

, 12 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Check File type at client side – jQuery

Whenever we use fileupload control on web pages, the common requirement is to validate its file type and size.

We usually find it difficult to validate file size on client side rather than at server side. As of now, there is no alternative script found that can achieve this. There are certain alternatives to achieve the above validation on client side but that are not browser compatible & as security level changes in browser, it stops functioning, so we are still not at that level of trust that we can check file size at client side using jQuery/JavaScript.

Although it is possible to validate filetype using jquery/JavaScript and I am looking to do some coding for you to achieve the same, I hope this will help some developers to validate file type at client side rather than checking it on server.

Here is the JavaScript code that achieves the above functionality :

 <script src="Js/jquery-1.4.2.min.js" type="text/javascript"></script>

The above code explains itself a lot so there is no need to discuss further on it.

Here is the HTML markup that shows controls on the page:

<form id="form1" runat="server">
 <div>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="Button1" runat="server" Text="Upload"
    OnClientClick="return FileTypeValidate();" />
 </div>
</form>

This is a very simple, but very common scenario for the web applications & very effective if managed properly…

That's it, hope this will help !!!

Jay Ganesh


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sandeep Ramani
Technical Lead
India India
Sandeep is a passionate .NET developer.

He is also certified as Microsoft Certified Technologies Specialist - Web Applications Development with Microsoft .NET Framework 4.

He is also awarded as Microsoft Community Contributor of the year 2011.

He has also received several awards at various forums and his various articles got listed as "Article of the day" at ASP.NET Microsoft Official Website www.asp.net.

He has done MCA from Gujarat University.

Visit his Blog:
http://ramanisandeep.wordpress.com/


Area of Expertise:
C#, ASP.NET , AJAX, Java script, JQuery, JSON, XML, Web Services, WCF, SSIS 2005, SQL Server 2005/2008, ASP.NET MVC

He is fond of movies, music, cricket, hockey and boxing.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 13 Feb 2011
Article Copyright 2011 by Sandeep Ramani
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid