Problem using the ASP.NET FileUpload control in an UpdatePanel? - asp.net

I'm running into an issue where I have a FileUpload control in an UpdatePanel. When I attempt to save changes and upload the file, no file is found. If I remove the UpdatePanel everything seems to work fine.
Any ideas why this might be happening? And is there a work-around?

To upload a file you need to perform a full ASP.NET page postback, it does not operate over the partial postback method.
You'll need to register the button which "uploads" your file as a PostBackTrigger of the UpdatePanel's triggers.
There are lots of free (and non-free) AJAX file upload solutions, or you can easily create one, it's just a matter of putting your file upload control within an iframe and submitting the iframe page back to the server. It isn't really ajax, but it gives a visual impression of AJAX.

Related

How to Refresh page after Response.End

In my ASP.NET application on a button click i am writing a .pdf content dynamically and the I am allowing to download for a User
Now to download i used Response.End() and need to refresh a download count on a page
But due to Response.End it is not happening
Please suggest
And it will never happen - You can not refresh page after Response.End
The way you download the files is not the best one. Use a handler for the download files and a simple anchor to that file.
Examples / Similar :
file download by calling .ashx page
What is the best way to download file from server
Hide modal window after Response.End() in asp.net

force reload of aspx page from silverlight xaml

I've a Silverlight application that is called from a asp .net project. I have a link in the silverlight project that brings the user back to the asp.net project. I do not want this to happen in a new window.
At the moment, it returns me to the cached page. I want to force a reload of it.
Currently onclick event of the link invokes the following code:
HtmlPage.Window.Navigate(new Uri("http://ipaddress/menu.aspx"));
Any suggestions on how I could enforce menu.aspx to reload when called?
I found a solution..
SOLUTION
HtmlPage.Window.Navigate(new Uri("http://ipaddress/menu.aspx?"));
This results in the page being reloaded....
Try using:
HtmlPage.Document.Submit()
It should work if your .aspx target page you wish to reload is the current page.

Using uploadify as part of an asp.net webform?

I have a web form that requires users to fill out some information and upload an image.
What I don't understand:
If I use uploadify to select a file doesn't it upload it right away to the server? Is there a way to defer that until the user would click on a form submit button? Or at least not save it to the file system?
Most examples use a custom HttpHandler for uploading files, but my file upload is part of a form. Should I still use a HttpHandler for that?
Well, I'll try to answer all your many questions, one by one. But before anything, open the official documentation because I will rely on it for answers.
If I use Uploadify to select a file doesn't it upload it right away to the server?
As you can see on the first demo, you can have a anchor (or a button or anything) to trigger the upload start. The Uploadify don't upload nothing until it's done (if the property auto isn't true).
Is there a way to defer that until the user would click on a form submit button?
Like described above, yes. And it's the default way (since the default value of auto is false).
Or at least not save it to the file system?
While the button doesn't trigger the .uploadifyUpload() method, nothing goes to the server. But when the Uploadify starts sending, it will be handled by the server (with the HTTP Handler). The handler is the guy that save it to the file system.
Most examples use a custom HttpHandler for uploading files, but my file upload is part of a form. Should I still use a HttpHandler for that?
As described on the script property, you can point to any server-side language that will handle the HTTP Request containing the data. The HttpHandler is the right thing because it haven't any other processing before or after the code you write. It isn't hard. The official forum shows some samples. And here on StackOverflow we have many questions about it, like these: Getting Uploadify Working in C# and Uploadify not working with ASP.NET WebForms.
The server shouldn't save the file until it is actually actioned by a handler. The Uploadify is providing the UI control for the gathering of the files and feedback. There are some settable properties available to control whether you want the "Auto" upload behavior or not.
You still need some king of server side processing for saving the data and an HTTPHandler is the usual way to do it. The HTTPHandler just operates on what file information it gets from the browser as part of a multi-part form data.
Here is an answer that provides more information about Uploadify: Getting Uploadify Working in C#

Using devexpress HtmlEditor control has DXR.axd throwing 404

I am using a dev express control: ASPxHtmlEditor version 10.1. I am trying to create a simple that only has this control. Unfortunately the control does not render with any of its styles or images loaded. This happens over 20 times. The control does not have any of its styles and all of its images do not load on the control.
I am getting 404 exceptions similar to: "Failed to load source http://localhost:11238/DXR.axd?r=5_0"
The cause of this issue is that the web.config file did not contain our http handler registration. So, such requests were not properly handled and scripts and images did not come to the client. Once you open the page in the designer, the http handler was registered and the problem disappeared :)
The solution was to restart my machine and open the page the control was on in design mode to have it create all the controls it needs to render properly.

File uploading in AJAX updatepanel without full postback

I have a update panel, in the update panel I have fileupload control and button control, On button click, I need the file that I have upload in the fileupload control in updatepanel.
Exact scenario, I have 8 tabs on page, each tab contains too much information, One of the tab is Attachment, when user click on Add New Attachment Modal Popup shown, Modal contains detailsview in Updatepanel and in the detailsview I have fileupload control, when user hit save button, detailsview inserting event fired, In the inserting event I need the file that I have upload.
Please Note, My page is heavy and I don't want full postBack.
Does anyone have solution of this issue?
Advance thanks for your kind help.....
For solve this problem, Please see the following step.
Add ajax-upload to your detail view.
iframe-based uploader like Resource#1.
Silverlight-based & Flash-based uploader. I like this technique because it doesn't require any server-side script for display current upload status. But in HTML5, you can create this without using any web browser plug-in.
Commercial uploader like Resource#2. that use hidden iframe for uploading.
Upload file to temporary location.
System response the temporary location. Next, client keep temporary location in hidden input in detail form.
Keep temporary location with session_id. You can store it in database or Session variable depend on your framework.
When you click on the save button, the system will move the files to their real location
Note. System will automatically delete the expired file from the temporary location.
Resource
ASP.NET File Upload with Real-Time Progress Bar
ASP.NET File Upload like GMail (Commercial)
Update
After almost one year, I just found a great 3rd-parties control for this question. This is an open source plug-in of jQuery. It name Plupload that allows you to upload files using HTML5, Silverlight, Flash or normal forms and it provide some unique features such as upload progress, image resizing and chunked uploads.
You can try & test Plupload by click here.
Can't be done without co-operating binaries being installed on the client. There is no safe mechanism for an AJAX framework to read the contents of a file and therefore be able to send it to the server. The browser supports that only as a multipart form post from a file input box.
The problem is with the way the HTML file upload control works, has nothing to do with ASP.net, for the file upload control to work you need a full post of the form data. You can only simulate that your are not doing a full postback, by doing all the operation in a hidden iframe that does the actual uploading
The sites you see that do provide this functionality generally use flash or an iframe so that the postback occurs in the iframe and gives the illusion of an ajax request.
HTH
OneSHOT
I've tried swfupload (http://swfupload.org/), but do keep in mind that you have to jump through hoops if you're using forms authentication with non-IE browsers. This is apparently a flash bug, and it's not fixed in flash 10. I decided against using it in our framework because of this bug, but it was otherwise a great product.
I recommend the uploader widget from YUI. See http://developer.yahoo.com/yui/uploader/
I think you could use it to accomplish your goal. Your javascript would need to fetch the file back down to the client from the server after it completed its upload. But the page would not refresh--the upload is through flash and a hidden iframe. The download to show the file's contents to the user would be via ajax.
If the user does not "approve" the upload, then simply make another ajax call to the server to delete the file.

Resources