This is a migrated thread and some comments may be shown as answers.

[Solved] FileUpload in grid template with ajaxpanel

4 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 16 Apr 2009, 05:24 PM
Hi,
I have a regular asp:FileUpload in a template in a grid.
It works fine to upload if ajax is not enabled but with ajax it wont work.
Javascript errormessage:
Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
I have looked at your demo and to use onrequeststart on the panel,
http://demos.telerik.com/aspnet-ajax/ajax/examples/common/fileupload/defaultcs.aspx
but I cant figure out what's wrong!

<script type="text/javascript"
        function OnRequestStart(target, arguments) { 
            if (document.getElementById("FileUpload2") != null) { 
                var fileUpload = document.getElementById("FileUpload2"); 
                if (fileUpload.value != "") { 
                    arguments.set_enableAjax(false); 
                } 
            } 
        } 
</script> 
<telerik:RadAjaxPanel runat="server" ID="radAjaxPanel" Width="100%" LoadingPanelID="radAjaxLoadingPanel" ClientEvents-OnRequestStart="OnRequestStart"
     <telerik:RadGrid ID="RadGrid1" 
     ... 
     <EditFormSettings EditFormType="Template"
           <FormTemplate> 
                <input id="FileUpload2" type="file" runat="server" class="fileUpload" /> 
                <asp:Button ID="buttonUploadFile" Text="Ladda upp" runat="server" ValidationGroup="validationGroupFile" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' CommandArgument="File" />  



4 Answers, 1 is accepted

Sort by
0
Mattias
Top achievements
Rank 1
answered on 16 Apr 2009, 05:31 PM
Hmm, the javascript error is server side related.
The problem seems to be the javascript, it never finds "FileUpload2" to disable ajax, how can that be done?
0
Mattias
Top achievements
Rank 1
answered on 16 Apr 2009, 05:58 PM
Thanks to your excellent documentation I found the answer with the javascript,
http://www.telerik.com/help/aspnet-ajax/grduploadwithajaxenabled.html

But now, serverside, it wont find the uploaded file! :(

protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) 
        { 
            GridEditableItem gridItem = e.Item as GridEditableItem; 
 
                HttpPostedFile postedFile = ((HtmlInputFile)gridItem.FindControl("FileUpload2")).PostedFile;  
                 
                    if (postedFile.ContentLength > 0) 
                    { 
                       ... 
The posted file is null!


0
Mattias
Top achievements
Rank 1
answered on 16 Apr 2009, 06:28 PM
Hmm, it seems to work if I change to a RadUpload!
Well, well, I can use a RadUpload instead, but it would be nice to know why the asp:FileUpload wont work!


0
Rosen
Telerik team
answered on 21 Apr 2009, 06:34 AM
Hi Mattias,

Can you please try changing the form enctype to  multipart/form-data similar to the following:

<form runat="server" id="frm1" enctype="multipart/form-data"


Kind regards,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Mattias
Top achievements
Rank 1
Answers by
Mattias
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or