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

Inherits RadAsyncUpload and OnFileUploaded

8 Answers 108 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Aleksandar
Top achievements
Rank 1
Aleksandar asked on 10 May 2011, 09:26 PM
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

8 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 11 May 2011, 02:01 PM
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.

0
Aleksandar
Top achievements
Rank 1
answered on 11 May 2011, 10:46 PM
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...
0
Aleksandar
Top achievements
Rank 1
answered on 15 May 2011, 12:27 PM
Any news on this? At least acknowledgement that this is an issue (a bug) would help.

Alex
0
Peter Filipov
Telerik team
answered on 17 May 2011, 01:28 PM
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.

0
Aleksandar
Top achievements
Rank 1
answered on 17 May 2011, 11:27 PM
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
0
Aleksandar
Top achievements
Rank 1
answered on 18 May 2011, 07:22 AM
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


0
yiqiang
Top achievements
Rank 1
answered on 07 Dec 2011, 07:57 AM
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
0
Peter Filipov
Telerik team
answered on 07 Dec 2011, 11:14 AM
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
Tags
AsyncUpload
Asked by
Aleksandar
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Aleksandar
Top achievements
Rank 1
Peter Filipov
Telerik team
yiqiang
Top achievements
Rank 1
Share this question
or