Deactivate Buttons

Oct 8, 2008 at 3:06 PM
Edited Oct 8, 2008 at 3:08 PM
Who i deactivate the browse and upload button after complete a file transfer?
Thanks!
Coordinator
Oct 8, 2008 at 5:32 PM
Edited Oct 8, 2008 at 5:36 PM

You can use
/// <summary>
/// Optional name of a javascript function that will be called each time the file is uploaded to the server.
/// As an argument to the function will be passed and object with the following properties:
///
/// name - the name of the file
/// size - the size of the file in bytes
/// status - the status of the file (Selected = 1,Uploading = 2,Uploaded = 3,Cancelled = 4,Error = 5)
/// index - the index of the file
/// isLast
/// </summary>
public string FileUploadedJsFunc

<script language="JavaScript">
    function fileUploaded(obj){
        if(obj. isLast){
      documet.getElementById("<%=FileUploader.ClientID%>_BrowseButton").disabled = true
            documet.getElementById("<%=FileUploader.ClientID%>_UploadButton").disabled = true
       }
    }
</script>
        <fjx:FileUploader ID="FileUploader1"
                                FileUploadedJsFunc="fileUploaded" runat="server" >
...
        </fjx:FileUploader>

Oct 8, 2008 at 5:45 PM
Edited Oct 8, 2008 at 5:47 PM
Thanks for the fast respond.

The code works but the "BrowseButton" still actives.. If it's clicked, the "UploadButton" is activated...

Coordinator
Oct 8, 2008 at 6:14 PM
Well this is because the client adapter calls it right after I guess you'd have to use setTimeout

<script language="JavaScript">
    function fileUploaded(obj){
        if(obj. isLast){
            window.setTimeout(disableUpload, 200);
       }
    }
    function disableUpload(){
            documet.getElementById("<%=FileUploader.ClientID%>_BrowseButton").disabled = true;
            documet.getElementById("<%=FileUploader.ClientID%>_UploadButton").disabled = true;
   }
</script>
        <fjx:FileUploader ID="FileUploader1"
                                FileUploadedJsFunc="fileUploaded" runat="server" >
...
        </fjx:FileUploader>

Oct 8, 2008 at 6:21 PM
That works! but only in Internet Explorer. On Firefox 3, Safari and Chrome didn't work :(
Coordinator
Oct 8, 2008 at 6:45 PM
        function fileUploaded(obj){
           if(obj.isLast){
               window.setTimeout(disableUpload, 400);
           }
        }
        function disableUpload(){
            document.getElementById("<%=FileUploader1.ClientID%>_BrowseButton").firstChild.disabled = true;
            document.getElementById("<%=FileUploader1.ClientID%>_UploadButton").firstChild.disabled = true;
        }
Oct 8, 2008 at 7:39 PM
Thank you flajaxian! You are the best! It works perfectly!
Dec 30, 2008 at 9:55 AM
Hi flajaxian,
first of all let me congrat for the excellent component.

I just downloaded latest release of Uploader and I'm trying to toggle the enabled status of browse/upload buttons via code you provided  here, but i can't get it work.

using FireBug in Firefox it gives me an error:
"document.getElementById("FileUploader1_BrowseButton") is null"
@ line " document.getElementById("FileUploader1_BrowseButton").firstChild.disabled = false;"

and, in fact, inspecting the html source of the aspx page in the browser, there is no BrowseButton.
Same errors with UploadButtons..

I already read this post and my app works quite the same way, but I would also like to disable upload while DropDownList.SelectedIndex is 0
So, are there any other ways to disable/enable Uploader buttons?

thanks,
parlato_edoardo


Coordinator
Dec 30, 2008 at 5:04 PM
Well the current version does not support disabling the upload, but as I am receiving more requests to do that I will be adding that in the next couple of days.
Dec 30, 2008 at 5:58 PM
It would be great! Keep me updated!

parlato_edoardo
Ps. (a little off topic) what about replacing Uploader with a standard System.Web.UI.WebControls.FileUpload when flash is not detected, instead of the "flash required" message?
Coordinator
Jan 2, 2009 at 3:10 AM
You can now use server side property Enabled = "true" or client side methods:

<%=FileUploader.ClientID%>.enable()

or

<%=FileUploader.ClientID%>.disable()

You can use if(swfobject.hasFlashPlayerVersion("1.0.0.0")){ ... } to detect if flash is there and implement your custom logic
Jan 5, 2009 at 4:18 PM
Thanks flajaxian!

At first tests seems new version does enable/disable correctly, but upload works only in IE, not in FF3. Am I wrong?
Coordinator
Jan 5, 2009 at 4:59 PM
I just tried it and I see no problems with FF3 upload ?!?
Coordinator
Jan 5, 2009 at 9:26 PM
OK I see the problem now, it is actually in all the browsers but it occurs in a specific circumstance - you have to disable the control before you have selected files. Flash doesn't get initialized in that case.

Please get the latest code or binaries for fix to that.
Jan 7, 2009 at 7:44 AM
Seems now all it's working correctly.

I found that there's still a conflict with
if (!User.Identity.IsAuthenticated){[do_something]}  as written in this thread @ post #3, but I hope I'll work around this.

thanks flajaxian for the really quick replies and fixes.
Jan 8, 2009 at 4:19 PM
Edited Jan 8, 2009 at 4:28 PM
I'm still having problems with authentication and FileUploader..
I removed all User.Identity.IsAuthenticated blocks and page work correctly, then I changed the web.config to require that only some privileged users can use the upload page.
Auth goes ok, but uploader now doesn't work, highlighting in red all the upload queue lines.
If I remove all kind of authentication then uploader works again...

What is going wrong? Anyone having same problem?

* EDIT: These problems are only in Firefox, IE does upload with and without authentication. *
Coordinator
Jan 8, 2009 at 4:30 PM
Did you do that:
http://flajaxian.com/flajaxian.com/FileUploader2.0Help.html#HowToOvercomeFlashBug
?
Jan 19, 2009 at 3:24 PM
Got it!

But still can't get this line work.
You can use if(swfobject.hasFlashPlayerVersion("1.0.0.0")){ ... } to detect if flash is there and implement your custom logic

Is it Js or C#? I can't find hasPlayerVersion property in the Uploader.
Coordinator
Jan 19, 2009 at 4:18 PM
This is JavaScript as part of swfobject the object included in Flajaxian Uploader.