Hello,
I have using the uplad event to send an email to the manager responsible for the user that is logged and uploading files. The error occurs when more then on user is logged at the same time. For example, if I have the following situation:
User A
Manager 1
File uploaded: X
User B
Manager 2
File uploaded: Y
User C
Manager 3
File uploaded: Z
When User A uploads, the email is correctly sent to Manager 1, displaying the name o User A and file X.
When User B uploads, the email is sent to Manager 1 (for the first event handled), displaying the name of user A and file Y.
In other words, the event sends correctly the file uploaded for User B but uses the information of User A regarding the user name and manager name. This occurs because the event is created on PageLoad of client A and the information is retained until the server resets.
When User C uploads, the email is sent to Manager 1 (again for the first event handled), displaying the name of user A and file Z.
I have tried passing the variables witth the name of User and email of Manger either via session and cookie. None of the them works. The information retained within FileVistaControl is always the one provided when the event is added on the first page load.
Could you provide a fix for this?
Thank you,
Mauro
Mauro
3/15/2009 7:57 AM
Mauro,
This is not a bug, you just need understand the events are static.
Please register the upload event (or also others) in Page_Load like this
If Application("Upload_Handler_Added") Is Nothing Then
AddHandler FileVistaControl.Uploaded, AddressOf FileVistaControl_Uploaded
'You can add other events just like the above line
Application("Upload_Handler_Added") = True
End If
This will make sure that the event is registered only when the your application is first accessed and not when the page is hit everytime. The control events are static so we use a Application variable to check existence.
Then in your event handler, write your code so that it knows it's executed out of context. For instance, you should access the current request by using HttpContext.Current.
Protected Sub FileVistaControl_Uploaded(ByVal sender As Object, ByVal e As FileVistaUploadedEventArgs) Handles FileVistaControl.Uploaded
' Do someting according to the user context that you can get from session. For example,
SendEmail(HttpContext.Current.Session("Username"), information)
End If
End Sub
Cem Alacayir
3/25/2009 6:15 PM