none
Autopostback takes a very long time if there is a file name in HtmlInputFile RRS feed

  • Question

  • Hello, 

    I have an ASPX page which basically has an Upload button, an HTML InputFile field (to let the user upload some file) radio button list (a simple yes and no). Depending on which option is selected, a dropdown list gets displayed, otherwise this drop down list is rendered invisible. Therefore, this RadioButton list (RBL) has AutoPostBack = true
    As mentioned before, there is an HTML Input File field which should logically be used only after the appropriate option on Radio Button list has been selected. However, if the user accidentally browses a file first (i.e. filling up the HTML Input File field) before selecting the appropriate option on the radio button list, and then changes the selection on the radiobutton list, the resulting auto post back could take approximately 30sec - 1 min if the file size is pretty big.

    It seems that the server is trying to do something with the file name on autopostback. Although after observing this behaviour, I did a thorough file search on my Inetpub directory and I did not find any files there that would support my inference. Please note that there is NO code in Page_Load function which deals with HTML Input File. The only time, the selected file physically gets stored on the server is when the user explicitly clicks the Upload Button.

    Attached below is some sample code for this webpage
    private void Page_Load(object sender, System.EventArgs e)
    		{
    			
    			try 
    			{
    
    				
    				if ( !Page.IsPostBack)
    				{
    					try
    					{
    						ValidateLogins(2);
    					}
    					catch (ThreadAbortException){}  //transfer cause threadabortexception, it need to ignored.
    					catch(Exception ex)
    					{
    						Context.Items.Add("ErrorMsg", ex.Message);
    						Server.Transfer("errormsg.aspx");
    					}
    					
    					//ButtonUpLoad.Attributes["onClick"] = string.Format("document.getElementById('{0}').value = document.getElementById('{1}').value", hiddenField1.ClientID, uploadFile.ClientID);
    					DataSet ds = new DataSet();
    					this.sqlDataAdapter1.Fill(ds);
    					ArrayList list = new ArrayList();
    
    					foreach(DataRow drow in ds.Tables[0].Rows) list.Add((string)drow[0]);
    					this.DropDownListObjectList.DataSource = list;
    					this.DropDownListObjectList.DataBind();
    				}
    				
    				
    			}
    			catch (ThreadAbortException){}
    			catch(Exception ex)
    			{
    				Context.Items.Add("ErrorMsg", ex.Message);
    				Server.Transfer("errormsg.aspx");
    			}	
    		}
    
    		#region Web Form Designer generated code
    		override protected void OnInit(EventArgs e)
    		{
    			//
    			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
    			//
    			InitializeComponent();
    			base.OnInit(e);
    		}
    		
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{    
    			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
    			this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
    			this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
    			this.RadioButtonListNameMatch.SelectedIndexChanged += new System.EventHandler(this.RadioButtonListNameMatch_SelectedIndexChanged);
    			this.Refresh.Click += new System.EventHandler(this.Refresh_Click);
    			this.ButtonUpLoad.Click += new System.EventHandler(this.ButtonUpLoad_Click);
    			this.hidden_upload.Click += new System.EventHandler(this.hidden_upload_Click);
    			
    	
    			this.Load += new System.EventHandler(this.Page_Load);
    
    		}
    private void RadioButtonListNameMatch_SelectedIndexChanged(object sender, System.EventArgs e)
    		{
    			
    			if (this.RadioButtonListNameMatch.SelectedItem.Value == "1")
    			{
    				this.DropDownListObjectList.Visible = true;
    				this.Refresh.Visible = true;
    			}
    			else
    			{
    				this.DropDownListObjectList.Visible = false;
    				this.Refresh.Visible = false;
    			}
    		}
    
    private void ButtonUpLoad_Click(object sender, System.EventArgs e)
    		{
    			// if the button is clicked, hide the Next button
    			ButtonUpLoad.Enabled = false;
    			string savedFileName;
    			string sqlstatement;
    			string continueURL = "";
    			DateTime uploadTime;
    			
    			try 
    			{
    				
    				string saveAsRoot  = Server.MapPath(null) + "\\UploadedFiles";
    				
    				
    				
    				// --- If there is a file to be uploaded
    				if (null != this.uploadFile.PostedFile) 
    				{
    
    					// --- Chop off the path and the extension to get only the file name
    
    					string postedFileFullLocalName = this.uploadFile.PostedFile.FileName;	
    					int idx = postedFileFullLocalName.LastIndexOf("\\");
    					string postedFileLocalName = postedFileFullLocalName.Substring(idx + 1); 
    					idx = postedFileLocalName.LastIndexOf(".");
    					string localNameWithoutSuffix =  postedFileLocalName.Substring(0, idx);
    
    
    					savedFileName = postedFileLocalName ;	// this is the name with which XLS file would be saved as a template
    					
    					
    					string saveAsName = saveAsRoot + "\\" + savedFileName;; 
    									
    
    					
    
    
    				// upload the file but delete the old one first
    						File.Delete(saveAsName);
    							
    						
    									
    						this.uploadFile.PostedFile.SaveAs(saveAsName);	// upload the file
    	
    				}	
    			}	// end try
    			catch (ThreadAbortException){}
    			catch(Exception ex)
    			{
    				Context.Items.Add("ErrorMsg", ex.Message);
    				Server.Transfer("errormsg.aspx");
    			}			
    		}
    
    #endregion
    I am developing this application in C# & ASP.NET 1.1 on Windows Server 2003 (x86). I would appreciate if anybody could explain (or help explain this behaviour). It is usually repeated whenever the user selects a file to upload (without hitting the upload button) and then changes the radio button list selection kicking off the autopost back

    Regards
    Asim
    • Moved by Harry Zhu Monday, October 12, 2009 4:37 AM (From:Visual C# Language)
    Thursday, October 8, 2009 3:18 PM

All replies

  • I don't see any grammar error in your code. Try an asp.net forum like forums.asp.net.


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
    Visual C++ MVP
    Thursday, October 8, 2009 7:48 PM
  • Hi,

    For the
    questions relating to asp.net ,please post to: http://forums.asp.net/.

    Thanks,
    Harry


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, October 12, 2009 4:36 AM