This is a migrated thread and some comments may be shown as answers.

ClientSide control of RadAsyncUpload visibility

1 Answer 202 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Jacob cheriathundam
Top achievements
Rank 1
Jacob cheriathundam asked on 26 Aug 2013, 09:58 PM
Based on some business rules on my form, I'd like to be able to disable/enable the RadAsyncUpload control on the client side.  Essentially, based on values entered by the user, the RadAsyncUpload control should either allow or disallow further uploads.  The one caveat is that if a user uploads files before the RadAsyncUpload control is disabled, those files SHOULD be uploaded when the page posts back.

I have tried using the set_enabled method, which does in fact disable/enable the control, however, if the control is disabled when the user submits the page, it seems like the FileUploaded server side event doesn't happen (the files are transported to the temporary folder, but the UploadedFiles parameter will be 0 and the FileUploaded event will not fire).

I've also tried disabling the "select" button of the control but "click" events in the telerik upload area still allow for browsing so disabling the button didn't really do anything for me. 

Any suggestions? 

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 27 Aug 2013, 07:12 AM
Hi Jacob,

If you are disabling the control using the set_enabled(false) method, then the uploaded files wont be accessible and hence the server side OnFileUploaded event wont fire which is the default behavior. Here is an approach I tried to fire the OnFileUploaded event for your scenario. Please have a look at the following code I tried.

ASPX:
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" MultipleFileSelection="Automatic"
    TargetFolder="~/Images/Img/" AllowedFileExtensions=".jpg,.zip" PostbackTriggers="RadButton2"
    OnFileUploaded="RadAsyncUpload1_FileUploaded">
</telerik:RadAsyncUpload>
<br />
<telerik:RadButton ID="RadButton1" runat="server" Text="Disable Control" AutoPostBack="false"
    OnClientClicked="disableAsyncupload">
</telerik:RadButton>
<telerik:RadButton ID="RadButton2" runat="server" Text="Upload" OnClientClicked="OnClientClicked"
    OnClick="RadButton2_Click">
</telerik:RadButton>
<asp:HiddenField ID="HiddenField1" runat="server" />

JavaScript:
<script type="text/javascript">
    function disableAsyncupload() {
        var radasyncupload = $find('<%=RadAsyncUpload1.ClientID %>');
        radasyncupload.set_enabled(false);
        document.getElementById("HiddenField1").value = "disabled";
    }
 
    function OnClientClicked() {
        var radasyncupload = $find('<%=RadAsyncUpload1.ClientID %>');
        //explicitly enabling the control temporarily for upload purpose.
        if (radasyncupload.get_enabled() == false) {
            radasyncupload.set_enabled(true);
        }
    }
</script>

C#:
protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
{
    string targetfolder = RadAsyncUpload1.TargetFolder;
    e.File.SaveAs(Path.Combine(Server.MapPath(targetfolder), e.File.FileName));
}
protected void RadButton2_Click(object sender, EventArgs e)
{
    //disabling the control based on hidden field value
    if (HiddenField1.Value == "disabled")
    {
        RadAsyncUpload1.Enabled = false;
    }
}

Thanks,
Shinu.
Tags
AsyncUpload
Asked by
Jacob cheriathundam
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or