-1

I have the fileupload control inside gridview edittemplate:

 <asp:TemplateField HeaderText="Template File" ItemStyle-HorizontalAlign="Left">
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblTemplateFileName" runat="server" Text='<%# Eval("TemplateFileName")%>'></asp:Label>
                                                                    </ItemTemplate>
                                                                    <EditItemTemplate>

                                                                        <asp:FileUpload ID="fuTemplate" runat="server" />
                                                                        <asp:RequiredFieldValidator ID="rfTemplateFile" Display="Dynamic" ControlToValidate="fuTemplate"
                                                                            runat="server" ErrorMessage="Select the Template File!" ValidationGroup="GRD"
                                                                            Text="*" ForeColor="Red"></asp:RequiredFieldValidator>

                                                                    </EditItemTemplate>
                                                                </asp:TemplateField>

GridView is inside the update panel:

<asp:UpdatePanel ID="upMain" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
...............
..............
</ContentTemplate>

</asp:UpdatePanel>

When through rowcommand I check fileuploader.Hasfile , and it always shows false although it has the file.

I tried having postbacktrigger for the grid as well as the fileuploader.

But it was not of use.

How can I deal with this problem?

Please guide me.

Have also tried adding :

Page.Form.Attributes.Add("enctype", "multipart/form-data");

On page load

sarin
  • 5,227
  • 3
  • 34
  • 63
C Sharper
  • 8,284
  • 26
  • 88
  • 151

1 Answers1

2

File Upload will not work with a partial post back. So just add this line at your page load

ScriptManager.GetCurrent(this).RegisterPostBackControl(this.YourGridviewId);

Or use PostBackTrigger.

<Triggers>
            <asp:PostBackTrigger ControlID="YourGridviewId" />
</Triggers>

Or You need special AsyncFileUpload control as defined in AjaxControl Toolkit.

<ajaxToolkit:AsyncFileUpload OnClientUploadError="uploadError"
     OnClientUploadComplete="uploadComplete" runat="server"
     ID="AsyncFileUpload1" Width="400px" UploaderStyle="Modern"
     UploadingBackColor="#CCFFFF" ThrobberID="myThrobber" />

You can check here.

Community
  • 1
  • 1
Litisqe Kumar
  • 2,512
  • 4
  • 26
  • 40