State is always empty, or how to store values for the uploader

Oct 23, 2008 at 3:20 PM
Hello again,

I have the following setup: Inside of a TabPanel i have a DropDown Menu for selecting persons. This dropwdown is inside of an updatepanel, in order to avoid a page reload every time i select something, which would cause the hosting tabcontainer to jump to the first page. Outside of the updatepanel resides my user control which contains the file uploader accompanied by a custom saver- adapter.

I must provide my adapter the value that is set in the dropdown. For doing this I tried to add the value to the uploader's state in code-behind. I have to make the value available to my custom adapter finally.

My problem now is that every time i upload something this state collection is empty, my values gone. I tried to workaround this by storing it in viewstate, which turned out to be empty also after clicking upload. my next guess would be to store it in the session, which basically works by setting the stored value in the adapter's property on each page_load of my control, but I have to initialize the my control with the fist element in the dropdown. I do this in the page_load of the page that hosts the tabpanel, but this is always called with Postback and !allback set to false when i hit upload, so each time i hit upload my selection stored in the session is overwritten with the defaut value...

So I'm completely stuck here. Since i need the value from the dropdown in my custom Adapter i cannot directly access it from session or viewstate. I'd like to have it in the Hashtable that is a parameter of the Adapter's ProcessFile Method, but I can't find a solution for this.
Oct 23, 2008 at 4:16 PM
So the call is not postback but there is a special way to pass state to the server:

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

then when th file is transfered you can get it as

    string stateInfo = this.Request.QueryString["MyKey"];

or here is a full example

<%@ Page Language="C#" AutoEventWireup="false" %>
<%@ Register TagPrefix="fjx" Namespace="com.flajaxian" Assembly="com.flajaxian.FileUploader" %>
<%@ Import Namespace="System.Collections.Generic" %>
<SCRIPT language="C#" runat="server">
override protected void OnInit(EventArgs e) {
     this.Load += new System.EventHandler(this.Page_Load);
protected void Page_Load(Object sender, EventArgs e){
      ddl1.DataSource = new KeyValuePair<string, string>[]{
           new KeyValuePair<string, string>("UploadFolder1", "UploadFolder1"),
           new KeyValuePair<string, string>("UploadFolder2", "UploadFolder2"),
           new KeyValuePair<string, string>("UploadFolder3", "UploadFolder3")

         ((com.flajaxian.FileSaverAdapter)FileUploader1.Adapters[0]).FolderName = this.Request["SelectedFolder"];
         FileUploader1.State.Add("SelectedFolder", ddl1.SelectedValue);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<form id="form1" runat="server">
<asp:DropDownList ID="ddl1" runat="server" DataValueField="Key" DataTextField="Value" AutoPostBack="true" />

Oct 24, 2008 at 7:20 AM
This is what I tried already.

In the OnItemChanged of my dropdown I set a value like FileUploader1.State.Add("MyKey", "MyValue"). The State collection contains 1 Item after that. Fine so far.
When I hit "Upload" the State Collection is empty again, and in the ProcessFile Method of my custom Upload Adapter the Hashtable also contains no items.
Oct 24, 2008 at 3:30 PM
Ok, I was not able to solve it with the State of the uploade.r My workaround was to put the upload control in its own page and display it as a Popup. Together with "Sesion" I was able to do what I wanted. But it is still very strange that both Viewstate and uploader state did not survive the click on the "upload" button...
Oct 27, 2008 at 4:36 AM
If your state is determened without postback you have to pass it on the client side with JavaScript.


<%=FileUploader1.ClientID%>.setStateVariable("someVar", "state");

Call this when your state changes