I started looking at the AjaxFileUpload control, specifically the ContextKeys property. However, I do not understand how to use it.
The documentation says of AjaxFileUpload that the ContextKeys is used to pass information to the server when a file is uploaded. But no examples are provided. Are there any examples online that I could look at?
Though such functionality not implemented (I believe it was planned but by some reasons was postponed), nothing protect you from implement it yourself. To do this you need to download AjaxControlToolkit source code and tweak it for your needs.
There will be a lot of points so you may to prepare a cup of coffee before :)
I'll show changes with name of file that must being changed.
Server/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs file
First of all, add ContextKeys property to the AjaxFileUploadEventArgs.cs file (it located in same folder):
After that open the AjaxFileUpload class code and change the OnPreRender method. Here is a part of this method with custom modifications:
That's all changes in server code we need. Now we need to modify the
Sys.Extended.UI.AjaxFileUpload
client class (file AjaxFileUpload.pre.js )Firstly let's modify
_html5UploadFile
method as below:As you can see above, we adding contextKeys to form data, posted with Ajax request.
The we need to modify the
_uploadInputElement
method:After all these changes you can set ContextKeys property in code-behind and get it value from
AjaxFileUploadEventArgs
argument of the UploadComplete event as below:Also, if you'll implement
OnClientUploadStarted
client-side event as proposed here link, you may pass to server your contextKeys from client: