Sachin Yadav
Sachin Yadav

Reputation: 187

FileUpload.Hasfile is returning false(What is the reason?)

I have a fileupload control on my .aspx page.

<asp:FileUpload ID="FileUpload1" runat="server" />

I am validating my control on my CS page.

if (FileUpload1.HasFile)

but this if condition is returning always false. I am not getting what is the actual reason! Can anyone help me in this?

Upvotes: 1

Views: 9893

Answers (2)

Sachin Yadav
Sachin Yadav

Reputation: 187

I have put my FileUpload Control into a Updatepanel. Then apply a trigger on those buttons from where data is submitting.

 <td>
      <asp:UpdatePanel runat="server" ID="updatepanel1">
          <Triggers><asp:PostBackTrigger ControlID="btnsubNxtClm" /></Triggers>
          <Triggers><asp:PostBackTrigger ControlID="btnsubmit" /></Triggers>
          <ContentTemplate>
          <asp:FileUpload ID="FileUpload1" runat="server" />
          </ContentTemplate>
      </asp:UpdatePanel>
</td>

Upvotes: 0

techspider
techspider

Reputation: 3410

FileUpload control is not compatible with UpdatePanel. You have two options

  1. Move the control outside of UpdatePanel
  2. If not possible, add a PostBackTrigger on the UpdatePanel

An example

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

For more information, you can refer to http://forums.asp.net/t/1142794.aspx

Upvotes: 3

Related Questions