Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a fileupload control. I want, when a user browse a image through this control of size more than 50 kb , an error message should display. How to do this?
I have one customvalidator as below...
XML
<asp:FileUpload ID="Fileupload1" runat="server"/>

<asp:CustomValidator ID="CustomValidator1"
                     runat="server"
                     ErrorMessage="not valid size"
                     Display="Dynamic"
                     ValidationGroup="I"
                     ControlToValidate="Fileupload1"
                     OnServerValidate="CustomValidator1_ServerValidate"
                     CssClass="validationCss">
</asp:CustomValidator>

C#
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (Fileupload1.HasFile)
        {
            if (Fileupload1.PostedFile.ContentLength &amp;gt;= 20960)
            {
                args.IsValid = false;
               // this.ModalPopupExtender1.Show();
            }
            else
            {
                args.IsValid = true;
            }
        }
    }

My validation is working, but when i click on the done button.
I want error message before I click the button.
Please help.
Posted
v3
Comments
[no name] 29-Oct-12 4:52am    
file upload image validation c# client side

https://www.google.co.in/search?q=file+upload+image+validation+c%23&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-beta#hl=en&client=firefox-beta&hs=e06&rls=org.mozilla:en-US%3Aofficial&sclient=psy-ab&q=file+upload+image+validation+c%23+client+side&oq=file+upload+image+validation+c%23+client+side&gs_l=serp.3...9995.13028.0.13392.14.13.0.0.0.0.251.1995.1j9j3.13.0...1.0...1c.1.KNiQ9qiKBrE&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&fp=500143d3cb9800f1&bpcl=35466521&biw=1920&bih=987

you don't need to write code for "Page_ClientValidate("groupName")"
because it's predefined when we use any validation control on the page
then the asp.net allow you to validate field value using this method....

you just call this function it will work..

I hope you understand..

because my English is poor.. :(
 
Share this answer
 
Comments
sanrai 2-Nov-12 1:57am    
but every time its showing me alert() even my page return true or false.
How i get some good tutorial about this
Hey why should not you try javascript


JavaScript
<script type="text/javascript">
function OnBrowse()
{
if(Page_ClientValidate("I"))
{
///Your login here......
alert("something....");
return false;
}
return true;
}
</script>
call this javascript function to fileupload "onchange" event....
 
Share this answer
 
v2
Comments
sanrai 1-Nov-12 1:12am    
how to write code for Page_clientValidate("I"))

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900