.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Server side validation of Fileupload control not working

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net


I've tried this method in my code behind to try and validate that the Fileupload control has a file or not. I get the error message the the event "Server Validate" cannot be found. Can anyone tell why? Thanks.

Public Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate

' Get file name

        Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl("uploadAvatar"), FileUpload)

        Dim UploadFileName As String = uploadAvatar.PostedFile.FileName

        If UploadFileName = "" Then
            ' There is no file selected
            args.IsValid = False
            Dim Extension As String = UploadFileName.Substring(UploadFileName.L

View Complete Post

More Related Resource Links

server side validation to file upload control in asp.net



how to validate a file upload control to allow  maximum "100kB" Size images.if exceed it should fire a asp validation"file size must be 100KB maximum".


Many Thanks in Advance. 

How to use server side validation to ensure image field is not null


I'm having trouble accomplishing the above. Below is all the mark up and code. I'm not getting error messages, but the validate image function is not working (fileupload portion is working ok).

In my attempt below---not sure if it's the simplest or best validation approach anyway---the "UserId" parameter appears during rendering to be empty---but in most methods I have it successfully containing or referring to the logged-in user's identification.

Following is the control that refers to the image field (page = advertisement.aspx):

<asp:Image ID="Image" runat="server" ImageUrl ='<%#Eval("UserId","Image.aspx?UserId={0}") %>'


Following is the successful code behind for the page image.aspx referred to above (page = image.aspx.vb):

Partial Public Class Image

    Inherits System.Web.UI.Page

    Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Request.QueryString("UserId") IsNot Nothing Then

            ' Get the connection string from Web.config.

            Using conn As New Sq

Server-side validation on an Entity Framework required field (property) does not work!

Has anyone had issues getting server-side validation on an Entity Framework required field (property) to work? The data type is a string (nvarchar). Server-side validation for required fields of other data types WORK fine. Only string fields have issues. I get the following error on UpdateModel(obj); of my POST method within the controller. Exception Details: System.Data.ConstraintException: This property cannot be set to a  null value.Source Error: Line 4500:                OnTextChanging(value);Line 4501:                ReportPropertyChanging("Text");Line 4502:                _Text = StructuralObject.SetValidValue(value, false);Line 4503:                ReportPropertyChanged("Text");Line 4504:                OnTextChanged(); I've even tried data annotations like this but it seems to get ignored.     [MetadataType(typeof(ObjMD))]     public partial class Obj     {    

Getting an error using FileUpload Control on a server.

Hello FriendsI m getting a problem while executing the following code for my website.This code works perfactly on localhost but when I use d same code on my webpage on the server it does nothing...even it doesnt return any error msg.Plz help me...protected void BtnUpload_Click(object sender, EventArgs e) {        int intFileSizeLimit = 1000;               string strFileNameWithPath = FileUpload1.PostedFile.FileName;               string strExtensionName = System.IO.Path.GetExtension(strFileNameWithPath);              string strFileName = System.IO.Path.GetFileName(strFileNameWithPath);           int intFileSize = FileUpload1.PostedFile.ContentLength / 1024;                              strExtensionName = strExtensionName.ToLower();        if (strExtensionName.Equals(".doc") || strExtensionName.Equals(".txt") || strExtensionName.Equals(".docx"))        {      

Treeview web server control client side evnts

HiI'm using Treeview control with asp.net 2.0. I would like to know how to get the client side events working. I don't want a post back for every little thing i do with the Treeview. Particularly i want to catch the node click event on the client side using java script, i want to enable/disable buttons based on the selected node. Is this possible? i tried some examples available on net but doesn't seem to be working. Please help me.. can someody give a working example....John 

User Control Validation is not working properly

In my Website I have header control (header.ascx) and footer control (footer.ascx)In header.ascx one textbox and one button is there. Textbox meant for accepting search string.In footer.ascx one textbox and one button is there. Textbox meant for accepting Email-Id.Now in validation of header.ascx I had done blank checking by JavaScript. And in validation of footer.ascx  I had done blank-checking and e-mail checking by javascript.In both the control the textbox and the button both resides under Panel control whose DefaultButton property set to the respective button ids. So that if User write write something and press ENTER key from keyboard then it should do whatever respective Button_Clicks will do.Now My problem is suppose I place the mouse cursor in footer.ascx's textbox and press the ENTER key it validates properly but after that if I place the cursor inheader.ascx's textbox and press the ENTER then it is not working. Again If I do the opposite then also first one will fire but in case of second it is not firing .......

Server Side Validation for SharePoint 2007 Form Fields


Hi Guys,

Need to validate NewForm.aspx and EditForm.aspx of SharePoint custom list. My current implementation is by using JavaScript. It's working fine.

Someone suggested JavaScript is not a good approach.I am unable to fetch ids dynamically by JavaScript only for few fields (people picker, calendar control) and in that case i have hard coded the ids. hardcoding is always a bad approache.

Is there any way to validate those mentioned form at server side? Is it really good way to think that my validation can put inside Event Handler?

thanksArup MCTS - SharePoint

Play Sudoku

Server control validation


Hi there,

I am writing a server control and I am looking for a way to inform the developer that one of the parameters that she passed to the server control is missing or is wrong.

How do I do that ?

get full path from fileupload control in client side???


<script type="text/javascript" >

        function SetA()

                    document.form1.action = 'Default.aspx?fileName='+document.getElementById('FileUpload1').value;
    <form id="form1" runat="server">
        <asp:FileUpload ID="FileUpload1" runat="server"  />
        <asp:Button ID="btnupload" runat="server" Text="Upload" OnClientClick="SetA()" />



here in the  javascript function i need send full path of upload control?


please help in this situation? if anybody knows other way of sending full path please tell?


thank you,

client side functionality in a custom server control using vb?



is it posible to add client side functionality to a custom server control in vb.net?

i am looking at msdn library and there is no code for vb :/ http://msdn.microsoft.com/en-us/library/aa719700%28v=VS.71%29.aspx

I fount this on MSDN Library Adding Client Capabilities to a Web Server Control

What i'm trying to do is to add some client functionality to my control, so that you can get or set some properties/values on client side. From the above link i see  that this is doable with Ajax Server Control, but i don't have it, i have Custom Server Control. Can i do this with Custom Server Control and how?

Thank you.

Server Side CustomValidator not working


When I use the CustomValidate for server side validation, it doesn't seem to execute the server code. All my server code does (at the moment) is set args.IsValid = false; But everytime I run it, if I put anything in the textbox I'm validating, it passes. I put a break in the server code and it doesn't break. I've set the "ControlToValidate" to the right text box.

What am I missing? What other properties need setting for it to work?

 I'm new to ASP and VS2005 so I'm probably missing something.


How can I retrieve the value if a server side control value whose value is updated on client side on


I have a hidden variable and its value is being updated using javascript(client side) which I make a call from server side code. 

After making the call I am not able to retrieve the updated value from Server side variable.

I went through this forum http://forums.asp.net/p/1289684/3668484.aspx but not able find a way how to implement functionality with IFRAME.

Please provide me some sample code. I am trying to call the client side code and retrieve the updated value from server side in page_load event.


Do Ajax Toolkit Extenders participate in server side validation?


If I use the extenders (for example mask edit) in place of some of the built in validators such as RegularExpressionValidator for exampe, will Page.Validate() still be called automatically and perform server side validation using the extenders?

how to convert simple html to asp.net control( server side useing C#,Jquery,xml,xslt)


input form 
<FORM METHOD=POST ACTION="mailto:someone@$nailmail.com" ENCTYPE="text/plain"> <table border=0 cellspacing=0 cellpadding=2> <tr> <td colspan=2> <font size=2 face="arial" color="#000000"> <INPUT type="text" name=URL size=17 value="http://"> :Your URL<BR> <INPUT type="text" name=user size=17> :Your Username<BR> <INPUT type="text" name=email size=17> :Your E-mail </font> </td> </tr> <tr> <td> <font size=1 face="arial" color="#000000"> <INPUT name=subscribe type=radio value="yes" CHECKED> subscribe<BR> <INPUT name=subscribe type=radio value="no"> unsubscribe<BR> </font> </td> <td> <SELECT name="choices" size=1> <OPTION selected> OPTIONS <OPTION> OPTION 1 <OPTION> OPTION 2 <OPTION> OPTION 3 <OPTION> OPTION 4 <OPTION> OPTION 5 </SELECT> </td> </tr> <tr> <td colspan=2> <font size=1 face="arial" color="#000000"> <INPUT type=checkbox name="html" value="sendme" CHECKED> i can recive email as html<BR> <INPUT type=checkbox name="receipt"

uploading Image from client to server without using fileupload control



I have a requirement to read an image from client machine and to save the same in server, the path and filename of the image is fixed, i want to

done this task without using a fileupload control. Is there any way to accomplish this task?

Server Side Validation


Hiiii Coders,

I have a listbox which has a list of customers,now i want that user must select a customer from listbox before hitting a save button. Also i have a new button for new customer. Means in case of new customer user will click on new button and a textbox will become visible just below the listbox. So in case of new customer user must enter a new customer name in textbox before clicking on save button.

It is something like requiredfieldvalidation

Also i want validation on server side

plz rep asap

thanx and regards 

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend