Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 29, 2012 02:20 AM by chetan.sarode
Feb 28, 2012 02:10 PM|LINK
an UpdatePanel to the ASP.net page, and there's an "Upload" button that calls a server-side script. In the server-side script method, I need to access the value in a FileUpload object ("pdf_file"). However, the FileUpload object doesn't have a value when
the server-side script accesses it (even though I selected a value, and it shows in the FileUpload box). From what I understand, the "object" passed to the method is now the Control, instead of the Page, since I'm using the UpdatePanel. So, I tried getting
the Parent of the "object" (Control), etc, but there still wasn't a value. I have Googled my heart out for an answer to this, and can't seem to figure it out. Any help would be greatly appreciated!
Here's the ASP page...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" Async="true" %>
<!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" >
<form id="form1" runat="server">
<asp:ScriptManager ID="MainScriptManager" runat="server" EnablePartialRendering="true" />
<asp:UpdatePanel ID="pnlTable" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<asp:FileUpload ID="pdf_file" runat="server" />
<br /><br />
<asp:Label runat="server" id="status_label" text="" />
<asp:HiddenField ID="hidden_products" runat="server" />
<asp:GridView ID="grid" runat="server" onrowdatabound="grid_RowDataBound"
<asp:Button ID="upload_button" runat="server" Text="Upload" onClientClick="submit();" onclick="upload_button_Click" />
<asp:AsyncPostBackTrigger ControlID="upload_button" EventName="Click" />
Here's the (first part of the) server-side method...
protected void upload_button_Click(object sender, EventArgs e)
//Control ctl = (Control)sender;
//String ctlType = ctl.Parent.GetType().ToString();
//HtmlForm form = (HtmlForm)ctl.Parent;
//FileUpload pdfUpload = (FileUpload)form.FindControl("pdf_uploader");
//lblStatus.Text = "upload_button_Click";
string file_name = pdf_uploader.FileName;
// Save temp copy of pdf on server
Random random_gen = new Random();
int rand = random_gen.Next();
string temp_pdf_path = "c:/temp/base_pdf_" + rand + ".pdf";
IEnvelope aoi = Get_Extent(temp_pdf_path, temp_xml_path,true);
Feb 28, 2012 03:52 PM|LINK
I had the same problem, in the end I used a jQuery file upload tool like this one:
Suggest you try the same but have a look at other plugins too that might suit your needs better.
Feb 29, 2012 02:20 AM|LINK
File upload doesn't work with updatepanels. It's a known issue and the latest AJAX Control Toolkit has an AsyncFileUpload control to remedy this problem.
See here building AJAX enabled File Upload control