Inherits RadAsyncUpload and OnFileUploaded

9 posts, 0 answers
  1. Aleksandar
    Aleksandar avatar
    52 posts
    Member since:
    Jul 2012

    Posted 10 May 2011 Link to this post

    For some reason, I am not getting OnFileUploaded to fire when I inherit from RadAsyncUpload in my custom web server component. Could someone tell me whether this is possible or not?

    Regards,
    Alex
  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 11 May 2011 Link to this post

    Hello Aleksandar,

    I've just tried that and it seems to work fine. Here is my code:

    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var foo = new Foo();
            Form.Controls.Add(foo);
            foo.FileUploaded += new FileUploadedEventHandler(foo_FileUploaded);
        }
     
        void foo_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            Response.Write("Test");
        }
    }
     
    public class Foo : RadAsyncUpload
    {
        public int Fooo { get; set; }
    }

    Does this work on your side?

    Regards,
    Genady Sergeev
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. Aleksandar
    Aleksandar avatar
    52 posts
    Member since:
    Jul 2012

    Posted 11 May 2011 Link to this post

    Hi Genady,

    This is what I am talking about:

    <DefaultProperty("Property_Is_deleted"), ToolboxData("<{0}:ClassName runat=server></{0}:ClassName>")> _
    Public Class ClassName
        Inherits RadAsyncUpload
      
        Protected Overrides Sub OnInit(e As System.EventArgs)
            MyBase.OnInit(e)
            MyBase.Skin = "Windows7"
            MyBase.EnableEmbeddedBaseStylesheet = True
            MyBase.EnableAjaxSkinRendering = True
        End Sub
      
         Protected Overrides Sub OnFileUploaded(e As Telerik.Web.UI.FileUploadedEventArgs)
            MyBase.OnFileUploaded(e) ' This does not fire
        End Sub
      
        Protected Overrides Function OnValidatingFile(e As Telerik.Web.UI.Upload.ValidateFileEventArgs) As Boolean
            Return MyBase.OnValidatingFile(e) ' Neither this fires 
        End Function
      
        Protected Overrides Sub CreateChildControls()
            MyBase.CreateChildControls()
            Me.OnClientAdded = "bor_ImageUpload_OnClientAdded"
            Me.OnClientFileUploaded = "bor_Open_ImageUpload_FileUploaded"
            Me.OnClientDeleting = "bor_Open_ImageUpload_ImageRemoved"
            Me.OnClientFileUploadFailed = "bor_Open_ImageUpload_UploadFailed"
            Me.MaxFileInputsCount = 1
            Me.OverwriteExistingFiles = True
            Me.MultipleFileSelection = Telerik.Web.UI.AsyncUpload.MultipleFileSelection.Disabled
            Me.InitialFileInputsCount = 1
            Me.ReadOnlyFileInputs = True
            Me.ControlObjectsVisibility = ControlObjectsVisibility.None
            Me.AutoAddFileInputs = True
            Me.AllowedFileExtensions = {"jpg", "jpeg", "png", "gif"}
            Me.InputSize = 10
            Me.TargetFolder = "~/TargetFolder"
        End Sub
    End Class

    Above does not work for me. Or I might be doing something wrong. So the question is: How do I inherit RadAsyncUpload in a custom class? OnFileUploaded fires on a page level, but does not fire on a class level.
    Looking forward for resolution for this as it stops planned development...
  4. Aleksandar
    Aleksandar avatar
    52 posts
    Member since:
    Jul 2012

    Posted 15 May 2011 Link to this post

    Any news on this? At least acknowledgement that this is an issue (a bug) would help.

    Alex
  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 17 May 2011 Link to this post

    Hi Aleksandar,

    OnFileUploaded is an event handler and it is not possible to override it. Please attach a handler to FileUploaded event.
    OnClientValidationFailed
    is a client side event.

    Here is a sample code:
    Imports Telerik.Web.UI
     
     
    Partial Class InheritAsyncUpload
        Inherits System.Web.UI.Page
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
     
            Dim asyncClass As New ClassName()
     
     
            Form.Controls.Add(asyncClass)
            AddHandler asyncClass.FileUploaded, AddressOf FileUploadedHandler
     
     
        End Sub
     
     
        Sub FileUploadedHandler(ByVal sender As Object, ByVal args As FileUploadedEventArgs)
     
            'some logic here
     
     
        End Sub
     
        
    End Class
     
    Public Class ClassName
        Inherits RadAsyncUpload
     
        Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
            MyBase.OnInit(e)
            MyBase.Skin = "Windows7"
            MyBase.EnableEmbeddedBaseStylesheet = True
            MyBase.EnableAjaxSkinRendering = True
        End Sub
     
        'Protected Overrides Sub OnFileUploaded(ByVal e As Telerik.Web.UI.FileUploadedEventArgs)
        '    MyBase.OnFileUploaded(e) ' This does not fire
        'End Sub
     
        'Protected Overrides Function OnValidatingFile(ByVal e As Telerik.Web.UI.Upload.ValidateFileEventArgs) As Boolean
        '    Return MyBase.OnValidatingFile(e) ' Neither this fires
        'End Function
     
        Protected Overrides Sub CreateChildControls()
            MyBase.CreateChildControls()
            'Me.OnClientAdded = "bor_ImageUpload_OnClientAdded"
            'Me.OnClientFileUploaded = "bor_Open_ImageUpload_FileUploaded"
     
            'Me.OnClientFileUploadFailed = "bor_Open_ImageUpload_UploadFailed"
            Me.MaxFileInputsCount = 1
     
            Me.MultipleFileSelection = Telerik.Web.UI.AsyncUpload.MultipleFileSelection.Disabled
            Me.InitialFileInputsCount = 1
     
     
            Me.AutoAddFileInputs = True
            Me.AllowedFileExtensions = {"jpg", "jpeg", "png", "gif"}
            Me.InputSize = 10
            Me.TargetFolder = "~/TargetFolder"
        End Sub
    End Class


    All the best,
    Peter Filipov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Aleksandar
    Aleksandar avatar
    52 posts
    Member since:
    Jul 2012

    Posted 17 May 2011 Link to this post

    Hi Peter,

    Please forget the page for now, I am inheriting RadAsyncUpload in custom server control (as in my previous code) and within the control, I need to know when the file is uploaded. Again, this event fails to trigger WITHIN the control for some reason:

    Protected Overrides Sub OnFileUploaded(ByVal e As Telerik.Web.UI.FileUploadedEventArgs)
            MyBase.OnFileUploaded(e) ' This does not fire
    End Sub

    How do I know when OnFileUploaded event executes from WITHIN the control inheriting from RadAsyncUpload?


    Regards,
    Alex
  7. Aleksandar
    Aleksandar avatar
    52 posts
    Member since:
    Jul 2012

    Posted 18 May 2011 Link to this post

    The solution:

    AddHandler to FileUploaded event:
    Protected Overrides Sub OnInit(e As System.EventArgs)
            MyBase.OnInit(e)
            AddHandler MyBase.FileUploaded, AddressOf OnMyFileUploaded
    End Sub

    And then just create the event and capture uploaded file

    Private Sub OnMyFileUploaded(sender As Object, e As Telerik.Web.UI.FileUploadedEventArgs)
    'Capture file here
    End Sub


    Regards,
    Alex


  8. yiqiang
    yiqiang avatar
    3 posts
    Member since:
    Sep 2011

    Posted 07 Dec 2011 Link to this post

    Hi peter,

    is there ValidatingFile event on RadAsyncUpload?

    I just want filter out ".exe" and ".dll" to upload using RadAsyncUpload before physical upload.

    Thanks,

    Liu
  9. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 07 Dec 2011 Link to this post

    Hello Yiqiang,

    To validate file extension you need to set AllowedFilesExtension property. Indeed RadAsyncUpload does not provide validation event. Here is the list with client-side events.

    All the best,
    Peter Filipov
    the Telerik team
    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 their blog feed now
Back to Top