AJAX: FileUpload control inside an UpdatePanel

by Brad 23. January 2008 21:53

UpdatePanels work fine with almost all controls, one control that it does 'break' however is FileUpload. If you try and upload a file it will seem to work - but if you check FileUpload.HasFile it will always return false. Rubbish if you've got an UpdatePanel in your MasterPage! However there is a solution, in fact it's not the UpdatePanel that breaks it, but the asynchronous PostBack instead. So a neat trick is to register the button you're using to cause the upload to use a normal PostBack. This can be done as follows:

this.ScriptManager.RegisterPostBackControl(btnUpload);

Then when the user clicks the upload button they'll get a normal PostBack (and therefore an uploaded file), while all the other controls on the page will continue to operate asynchronously - no need to re-jig the whole layout of the site.

Tags:

ASP.NET AJAX | C#

Comments

8/7/2008 11:30:11 PM #

fdsfsdfdsf fgfdg

sunil |

11/17/2008 8:52:30 AM #

Superb

Rag |

12/30/2008 9:09:41 PM #

        protected void Page_Load(object sender, EventArgs e)
        {
            //required to enable functionality of the FileUpload control in an AJAX UpdatePanel
            ((ScriptManager)this.Master.FindControl("ScriptManagerMain")).RegisterPostBackControl(btnUpload);

            if (!IsPostBack)
            {
                BindData();
            }
        }

Andrew Rosca |

2/25/2009 10:13:58 AM #

Still not working for me...

Rajesh |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar