This project has moved. For the latest updates, please go here.

document.getElementById('InputFile1') return NULL

Nov 2, 2010 at 8:08 AM

Hi,

I am accessing InputFile control from following code

//this is in java script

function FileExtensionIsValid(sender, args) {
            // use the client id of the file upload
             var nuUpload = document.getElementById('InputFile1');

             // empty upload  control is valid
             var isValid = (nuUpload.value.length = 0)
             if (! isValid) {
                 isValid = FileTypeValidator(nuUpload.value, ['doc', 'xls', 'jpg', 'jpeg', 'pdf', 'tif', 'tiff'])
             }
             args.IsValid = isValid;
        }

 

//this is in .aspx page cs file

protected void FileTypeCheck(object source, ServerValidateEventArgs args)
        {
            InputFile fileControl = (InputFile)this.FindControl("InputFile1");
            Boolean isValid = true;
            if (fileControl.FileName.Length > 0)
            {
                String origName = args.Value;
                String fileExt = origName.Substring(origName.LastIndexOf(".")).Replace(".", "").ToLower();
                if (fileExt != "pdf" && fileExt != "jpg" && fileExt != "tiff" && fileExt != "tif" && fileExt != "doc" && fileExt != "xls")
                {
                    isValid = false;
                    //LabelErrorMessage.Text = fileExt;
                }
            }
            args.IsValid = isValid;
        }

 

both return NULL when i perform FindControl or getElementbyID

 

please help me on this.

raj

Nov 8, 2010 at 5:10 PM

I ran into a similar issue and the problem was that .NET changes the name of InputFile1 in the source.

Try this for the javascript:

var nuUpload = document.getElementById('<%= InputFile1.clientID %>');

-Brian