I am new to the AJAX world, and have been given an ASP page, with javascript that contains dojo, and asked to use some AJAX on it. I thought the ASP.net AJAX solution would be simple enough - just use the UpdatePanel... but maybe I'm wrong :-) So, I added
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!
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.
ruth_l
0 Points
1 Post
Use value from form in server-side script
Feb 28, 2012 02:10 PM|LINK
I am new to the AJAX world, and have been given an ASP page, with javascript that contains dojo, and asked to use some AJAX on it. I thought the ASP.net AJAX solution would be simple enough - just use the UpdatePanel... but maybe I'm wrong :-) So, I added 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" > <head runat="server"> <title>Demo</title> <script type="text/javascript" src="./js/main.js"></script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="MainScriptManager" runat="server" EnablePartialRendering="true" /> <asp:UpdatePanel ID="pnlTable" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false"> <ContentTemplate> <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" onselectedindexchanged="grid_SelectedIndexChanged"> </asp:GridView> <asp:Button ID="upload_button" runat="server" Text="Upload" onClientClick="submit();" onclick="upload_button_Click" /> </ContentTemplate> <%-- <Triggers> <asp:AsyncPostBackTrigger ControlID="upload_button" EventName="Click" /> </Triggers> --%> </asp:UpdatePanel> </div></form></body></html>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"; if (pdf_uploader.HasFile) { 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"; pdf_uploader.SaveAs(temp_pdf_path); IEnvelope aoi = Get_Extent(temp_pdf_path, temp_xml_path,true); } }breath2k
Contributor
2101 Points
821 Posts
Re: Use value from form in server-side script
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:
http://blueimp.github.com/jQuery-File-Upload/
Suggest you try the same but have a look at other plugins too that might suit your needs better.
chetan.sarod...
All-Star
65749 Points
11148 Posts
Re: Use value from form in server-side script
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.
Refer: http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
See here building AJAX enabled File Upload control
http://aspalliance.com/1442_Building_AJAX_Enabled_File_Uploading_System_with_Progress_Bar_Using_ASPNET_20.all
http://geekswithblogs.net/rashid/archive/2007/08/01/Create-An-Ajax-Style-File-Upload.aspx
http://weblogs.asp.net/manojkdotnet/archive/2009/10/16/asynfileupload-control-and-its-validation.aspx
http://msmvps.com/blogs/luisabreu/archive/2006/12/14/uploading-files-without-a-full-postback.aspx
http://blogs.infragistics.com/blogs/tony_lombardo/archive/2007/04/09/file-uploads-where-s-the-ajax.aspx
http://www.codeproject.com/KB/aspnet/AJAXUpload.aspx
http://forums.asp.net/t/1207035.aspx
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.