Upload button causes neither postback nor callback

Jul 16, 2008 at 12:11 PM
When I click the upload button the page is reloaded and execution stops on my breakpoint in Page_Load. However the request is neither a postback nor a callback and I'm unable to obtain postback information from any of the other controls on the page. All of the other controls behave as if the page is being loaded for the first time with a new session. Could I be doing something wrong here?
Coordinator
Jul 16, 2008 at 4:24 PM
Most probably the javascript is not initialized its very hard to tell what's wrong based on your description
Jul 16, 2008 at 10:23 PM

JavaScript in the uploads control or elsewhere? Here is some example code to reproduce:

 

 

<cc1:FileUploader ID="fileUploader1" runat="server" FileListWidth="150" FileListRowWidth="150"></cc1:FileUploader>

 

 

protected void Page_Load( object sender, EventArgs e )
{
    if( this.IsPostBack || this.IsCallback ) {
        // Good!!!
    }
    else {
        // Bad!!!
    }
}

 

 

Coordinator
Jul 17, 2008 at 4:53 PM
A ok, sorry, I didn't understand your initial question well.

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

if(FileUploader1.FileIsPosted){
string stateInfo = this.Request.QueryString["MyKey"];
}

of 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){
if(!this.IsPostBack){
ddl1.DataSource = new KeyValuePair<string, string>[]{
new KeyValuePair<string, string>("UploadFolder1", "UploadFolder1"),
new KeyValuePair<string, string>("UploadFolder2", "UploadFolder2"),
new KeyValuePair<string, string>("UploadFolder3", "UploadFolder3")
};
ddl1.DataBind();
}

if(FileUploader1.FileIsPosted){
((com.flajaxian.FileSaverAdapter)FileUploader1.Adapters[0]).FolderName = this.Request["SelectedFolder"];
}else{
FileUploader1.State.Add("SelectedFolder", ddl1.SelectedValue);
}
}
</SCRIPT>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddl1" runat="server" DataValueField="Key" DataTextField="Value" AutoPostBack="true" />

<div> 
Jul 19, 2008 at 12:31 AM
Your code example does work. However, when I replace the DropDownList with the equivalent DevExpress ASPxComboBox it doesn't work and the selected value always comes out null after clicking the Upload button on the FileUploader. Now I think the standard Microsft DropDownList must be using ViewState and the DevExpress ASPxComboBox is probably using for variables, which require a postback to be present. The problem is I'm trying to use their TreeList control so I can't easily substitute it with a Microsoft one.

I appreciate that the problem is not directly with the file uploaded but is there any reason why the Upload button shouldn't cause a postback?
Coordinator
Jul 19, 2008 at 5:11 AM
Yes there is a reason postback is costly and there is no need to send the viewstate and and many variables together with the files. I am not familiar with ASPxComboBox and I will have no time to spend for studding it.
Jul 19, 2008 at 11:14 AM
OK, I tried saving the value of the ASPxComboBox in the page's ViewState when ever a new item is selected. The value in ViewState always comes out as null when I click the Upload button. I also tried using a standard Microsoft HiddenField instead of ViewState and it also comes back with a null value. So it seems that when the Upload  button is cliked there is neither ViewState nor postback data. Now I have no idea how the Microsoft DropDownList is making this work. If I could work out how they get around it then I could use the same technique as a workaround to get the TreeList control to work with the FileUploader.
Jul 23, 2008 at 1:04 PM
It seems I've been barking up the wrong tree and I should have studied your example code more carefully. The fact that the DropDownList was preserving the selected value without a postback was just coincidental and not relevant to your example. Your suggestions to use FileUploader1.State.Add("MyKey", "MyValue") works very well and has solved my problem at hand. Thanks.
Coordinator
Jul 23, 2008 at 4:25 PM
No problem Mahbouni, I am glad you resolved that.