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

Handle Select Button Event in Code-behind

1 Answer 92 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 03 Jun 2013, 10:49 PM

Hi,
 I have an aspx.cs page which uploads the RadAsyncUpload UploadedFiles collection to Azure per the following button click event. I've been asked to upload the files automatically, as soon as the user hits the RadAsyncUpload Select button, rather than having an extra button on the page, but not sure how to do this. Any help with this would be greatly appreciated.
I need to run code similar to the below....

protected void btnAttachFiles_Click(object sender, EventArgs e)
{
    Boolean isUploaded = false;
 
    for (int i = 0; i <= RadAsyncUpload1.UploadedFiles.Count - 1; i++)
    {
        try
        {
            Telerik.Web.UI.UploadedFile file = RadAsyncUpload1.UploadedFiles[i];
       
            // upload file to azure
            byte[] fileDataByteArray = new byte[file.InputStream.Length];
            file.InputStream.Read(fileDataByteArray, 0, (int)file.InputStream.Length);
            isUploaded = myAzure.UploadBlob(fileDataByteArray, RadAsyncUpload1.UploadedFiles[i]);
 
        }
        catch (Exception exc)
        {
            lblError.Text = exc.Message;
        }
    }
}

 

Thank you very much,
Randy Sullivan

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 06 Jun 2013, 03:39 PM
Hi Randy,

Handle the OnClientFilesSelected event and simulate a button click:

aspx:
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" OnClientFilesSelected="OnClientFilesSelected" />
      <telerik:RadButton ID="btnAttachFiles" runat="server" Text="Attach Files" OnClick="btnAttachFiles_Click" Visible="false"/>

javascript:
function OnClientFilesSelected(sender, args) {
    (document).getElementById('<%=btnAttachFiles.ClientID%>').click();
}

cs:
protected void btnAttachFiles_Click(object sender, EventArgs e)
{
    ...
}

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
AsyncUpload
Asked by
Randy
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or