write function in JavaScript
Note:- Only working with FireFox,Crome,Safari,Opera
for Internet Explorer check this page
function aditya(source, args)
{
arguments.isvalid = false;
fileupload = document.getElementById('<%= FileUpload2.ClientID %>');
file=fileupload.files[0];
if (file.size<1048576)
{
args.IsValid = true;
}
else
{
args.IsValid = false ;
}
return ;
}
use this function in Custom Validator Field
<asp:FileUpload ID="FileUpload2" runat="server" />
<asp:CustomValidator ID="abc" runat="server" ErrorMessage="Max File Size is 1 MB" ControlToValidate="FileUpload2" ClientValidationFunction="aditya"></asp:CustomValidator>
==========================================================================
Example:---
==========================================================================
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function aditya(source, args)
{
arguments.isvalid = false;
fileupload = document.getElementById('<%= FileUpload2.ClientID %>');
file=fileupload.files[0];
if (file.size<1048576)
{
args.IsValid = true;
}
else
{
args.IsValid = false ;
}
return ;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload2" runat="server" />
<asp:RegularExpressionValidator ID="ValidateResume" runat="server" ErrorMessage="Only pdf files allowed."
ValidationExpression="^.+\.(([pP][dD][fF]))$" ControlToValidate="FileUpload2" />
<asp:CustomValidator ID="abc" runat="server" ErrorMessage="Max File Size is 1 MB" ControlToValidate="FileUpload2"
ClientValidationFunction="aditya"></asp:CustomValidator>
</div>
</form>
</body>
</html>
Note:- Only working with FireFox,Crome,Safari,Opera
for Internet Explorer check this page
function aditya(source, args)
{
arguments.isvalid = false;
fileupload = document.getElementById('<%= FileUpload2.ClientID %>');
file=fileupload.files[0];
if (file.size<1048576)
{
args.IsValid = true;
}
else
{
args.IsValid = false ;
}
return ;
}
use this function in Custom Validator Field
<asp:FileUpload ID="FileUpload2" runat="server" />
<asp:CustomValidator ID="abc" runat="server" ErrorMessage="Max File Size is 1 MB" ControlToValidate="FileUpload2" ClientValidationFunction="aditya"></asp:CustomValidator>
==========================================================================
Example:---
==========================================================================
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function aditya(source, args)
{
arguments.isvalid = false;
fileupload = document.getElementById('<%= FileUpload2.ClientID %>');
file=fileupload.files[0];
if (file.size<1048576)
{
args.IsValid = true;
}
else
{
args.IsValid = false ;
}
return ;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload2" runat="server" />
<asp:RegularExpressionValidator ID="ValidateResume" runat="server" ErrorMessage="Only pdf files allowed."
ValidationExpression="^.+\.(([pP][dD][fF]))$" ControlToValidate="FileUpload2" />
<asp:CustomValidator ID="abc" runat="server" ErrorMessage="Max File Size is 1 MB" ControlToValidate="FileUpload2"
ClientValidationFunction="aditya"></asp:CustomValidator>
</div>
</form>
</body>
</html>
This does n't work in IE.
ReplyDeleteits not working in IE because fileupload.files[0]; is not supported by IE. this is working very fine in any other browser.
Deletehttp://criticalcodes.blogspot.in/2012/03/using-javascript-check-uploaded-file.html
Deletecheck this link i updated code.
It's asp.net right?what to do in PHP
ReplyDeleteCheck this
Deletehttp://criticalcodes.blogspot.in/2012/04/using-javascript-check-uploaded-file.html