RadGrid for ASP.NET

File upload in AJAX-enabled grid Send comments on this topic.
AJAX > What you should have in mind > File upload in AJAX-enabled grid

Glossary Item Box

File upload is not supported using AJAX calls. This is a limitation of the XmlHttpRequest component, used in all AJAX frameworks for asynchronous calls to the application. In order to upload a file you should perform a full page postback.

Fortunately, there is a workaround available which can allow you to upload files with AJAX-enabled grid. If you have button or other control, which normally does postbacks, you need to attach an event handler on the OnRequestStart client-side event of the RadGrid, which will disable the AJAX functionality if a specific button is clicked. Below are sample code snippets:

ASPX/ASCX Copy Code
<script type="text/javascript">
//on insert and update buttons click temporarily disables ajax to perform upload actions function conditionalPostback(e, sender)
{
     var re = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
     if (sender.EventTarget.match(re))
    {
         sender.EnableAjax = false;
    }
}
</script>
<
radu:radprogressmanager id="RadProgressManager1" runat="server"/>
<
rad:radgrid runat="server" id="RadGrid1" enableajax="true">
      
<clientsettings>
            
<clientevents onrequeststart="conditionalPostback" />
      
</clientsettings>
      
<mastertableview>
         
<columns>
              
<rad:grideditcommandcolumn />
              
<rad:gridtemplatecolumn uniquename="Upload">
                       
<itemtemplate> ... </itemtemplate>
                       
<edititemtemplate>
                           
<radu:radupload id="RadUpload1" runat="server" />
                       
</edititemtemplate>
             
</rad:gridtemplatecolumn>
        
</columns>
        
<editformsettings>
                 
<editcolumn uniquename="EditCommandColumn1"> </editcolumn>
        
</editformsettings>
     
</mastertableview>
</
rad:radgrid>

An online demo demonstrating the approach in reality can be viewed here.