views:

11

answers:

2

I have used file upload control of asp.net but I am getting empty string while saving.my code-

<asp:FileUpload ID="fuProductLogo" runat="server" CssClass="file paddBottom5px"  />

.cs code is-

if (fuProductLogo.PostedFile != null && fuProductLogo.PostedFile.ContentLength > 0)
                {
...
}

but the .PstedFile and .CountLength is coming zero but the same code is working fine in another page.Please help.

+1  A: 

There are several things to check here:

  • as @williem said, remove updatepanel from the form if you are using it
  • add enctype="application/x-www-form-urlencoded" in the form tag

Please remember to update your post after your code modifications and checks.

lakhlaniprashant.blogspot.com
the whole page is inside the update panel how can I put outside? and there is not form tag in my aspx code.
ppp
well, you cannot use update panels while uploading a form. if you are using master page, your form tag will be there
lakhlaniprashant.blogspot.com
A: 

If the FileUpload is in an UpdatePanel it will be cleared on each ajax-postback. You can use multiple UpdatePanels around the FileUpload control and keep the FileUpload out of them. Also make sure that the button that triggers the actual upload does a real postback, not an asyncpostback. Do this by adding the button to the PostbackTrigger of it's UpdatePanel or by taking it out of the UpdatePanel.

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="TextBox2" runat="server" />
        <asp:Button ID="Submit" runat="server" Text="Submit" />
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="Submit" />
    </Triggers>
</asp:UpdatePanel>  

You can also use an AsyncFileUpload control from the Asp.net Ajax Toolkit, it works inside an UpdatePanel but it is a little harder to get this to work.

Willem