Send Variables with the Files

Mar 22, 2011 at 3:51 AM

If you want to transfer some variables together with the files, you have to use State property. For example (server-side code):

FileUploader1.State.Add("MyKey", "MyValue");

The same can be done on client side with JavaScript:

<%=FileUploader1.ClientID%>.setStateVariable("MyKey", "MyValue");

or if the code is executed when the page is loaded you can use:

<script type="text/javascript">
function addFileUploaderState(){
<%= FileUploader1.ClientID %>.setStateVariable("MyKey1", "MyValue1");
<%= FileUploader1.ClientID %>.setStateVariable("MyKey2", "MyValue2");
}, 100);
if (window.addEventListener) window.addEventListener('onload', addFileUploaderState, false);
else if (window.attachEvent) window.attachEvent('onload', addFileUploaderState);

though in this case a better option would be to use server-side code.

Then in your server-side event you can access those variables from the Form collection of the Request object. For example:

  string myValue = HttpContext.Current.Request.Form["MyKey"];

Can anyone share with me how does this working?
i need to insert FileUploader1.State.Add("MyKey", "MyValue"); on upload page's Page_Load then get the value from the target page from this coding (string myValue = HttpContext.Current.Request.Form["MyKey"];)?
And what is the used for this send variable?