Handle Select Button Event in Code-behind

2 posts, 0 answers
  1. Randy
    Randy avatar
    12 posts
    Member since:
    Jan 2012

    Posted 03 Jun 2013 Link to this post

    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

  2. Hristo Valyavicharski
    Admin
    Hristo Valyavicharski avatar
    975 posts

    Posted 06 Jun 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top