Using Javascript with .net and ajax control kit

Hi,

I am using ajax control kit.

What i want to do is check the file size on the event OnclientUploadComplete with File uplaod how can i do this

Please help

R8VI
<cc1:AsyncFileUpload ID="asyncFileUpload1" runat="server" UploadingBackColor="LightGray"
                    CompleteBackColor="Lime" OnUploadedComplete="asyncUploadCompl" UploaderStyle="Modern"
                    ThrobberID="Throbber" OnClientUploadComplete="UploadComplete" OnClientUploadStarted="StartUpload"
                   /> 

//This doesnt work 
fucnction UploadComplete(sender, args) {
           if (document.getElementById("asyncFileUpload1").Postedfile.Contentlength > 47629) {
                document.getElementById('lblSt').innerText = 'File Sise to big';
            }
            else {
something else 
}
}

Open in new window

R8VIAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

krunal_shahCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
R8VIAuthor Commented:
Hi Krunal,

Thanks for this I have one problem with it now that if user uploads a file that is tooo big first and then tries to upload a file that is right it still doesnt upload i think its because of this line in the UploadComplete function

 if (textError.length > 0) {
                var text = document.getElementById("<%= errorText.ClientID %>");
                texttext.innerText = text.textContent = textError;

                sender._onError(textError); // it will raise the OnClientUploadError event  

                return;
            }

I think its this becasue the length is already > 0 because wrong file intitally

Please help

Thanks,

R8VI

PS posting code below


Ajax control 

                <cc1:AsyncFileUpload ID="asyncFileUpload1" runat="server" UploadingBackColor="LightGray"
                    CompleteBackColor="Lime" OnUploadedComplete="asyncUploadComplere" UploaderStyle="Modern"
                    ThrobberID="Throbber" OnClientUploadComplete="UploadComplete" OnClientUploadStarted="StartUpload"
                    Width="300px" OnClientUploadError="textError" />

Javascript functions 

 function UploadComplete(sender, args) {

            }

            var textError = $get("<%= errorText.ClientID %>").innerHTML;

            if (textError.length > 0) {
                var text = document.getElementById("<%= errorText.ClientID %>");
                texttext.innerText = text.textContent = textError;

                sender._onError(textError); // it will raise the OnClientUploadError event  

                return;
            }
            else {
                var text = document.getElementById("<%= errorText.ClientID %>");
                texttext.innerText = text.textContent = "Upload Successful";
                

            }

            var fileupload = document.getElementById("asyncFileUpload1");
   
            document.getElementById('lblSt').innerText = 'Uploading Completed.';


        }

        function textError(sender, args) {
            var text = document.getElementById("<%= errorText.ClientID %>");
            errorText.innerText = text.textContent = " ";
            errorText.innerText = text.textContent = "No Upload, ";

            if (document.getElementById('lblStatus').innerText != null) {
                document.getElementById('lblStatus').innerText = '';
                
            }
        }

        function StartUpload(sender, args) {
            var filesize = document.getElementById('lblFileSize');
            if (filesize != null) {
                document.getElementById('lblFileSize').innerText = ' ';
            }
            document.getElementById('lblStatus').innerText = 'Uploading Started.';


        }

c# method 

if (iSizeOfFile <= 47629)
                {

                    //save file 
                }

                else
                {
                    string textError = "File is bigger than 4KB.";

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "top.$get(\"" + errorText.ClientID + "\").innerHTML='" + textError + "';", true);  
                    return;

                }

Open in new window

0
masterpassCommented:
If you are planning for JS based solution to measure the file size and if you need a cross-browser solution, then the answer is no ... you can't measure the upload size .... Hoe ever if you want just in IE you can do it with activeX .. have a look

http://www.c-point.com/JavaScript/articles/file_access_with_JavaScript.htm
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.