views:

492

answers:

4

Hi! I'm using file upload in my site. I'm uploading word Document(Doc,Docx). Suddenly, it's not working. It is not getting the filename. It is showing empty!!! My Code is as follows:

<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">

<table width="100%" align="center">
    <tr>
        <td style="height: 21px" align="center">
            <span class="lbl"></span>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
                    <asp:Button ID="btnResumedload" Text="Download Resume" runat="server" BackColor="Maroon"
                        ForeColor="White" Font-Bold="true" OnClick="btnResumedload_Click" Height="27px"
                        Width="195px" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </td>
    </tr>
    <tr>
        <td align="center">
            <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                <ContentTemplate>
                    <asp:Button ID="btnUploadnew" Text="Upload New" runat="server" BackColor="Maroon"
                        ForeColor="White" Font-Bold="true" OnClick="btnUploadnew_Click" Height="30px"
                        Width="198px" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </td>
    </tr>
    <tr>
        <td align="center">
            <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                <ContentTemplate>
                    <asp:Button ID="btnDel" Height="30px" Width="198px" OnClientClick="return confirm('Are you sure?');"
                        BackColor="Maroon" ForeColor="White" Font-Bold="true" Text="Delete Resume" runat="server"
                        OnClick="btnDel_Click"></asp:Button>
                </ContentTemplate>
            </asp:UpdatePanel>
        </td>
    </tr>
    <tr>
        <td align="center">
            <asp:Label ID="lblmsg" runat="server" Font-Bold="True" ForeColor="Red" Visible="False"
                Height="17px" Width="855px"></asp:Label>
        </td>
    </tr>
    <tr>
        <td align="center">
            <span class="txt">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <%--<ajaxToolkit:AsyncFileUpload ID="fpResumenew" runat="server" Visible="false" />--%>
                        <asp:FileUpload ID="fpResumenew" runat="server" Visible="false" Width="226px" />
                    </ContentTemplate>
                    <Triggers>
                        <asp:PostBackTrigger ControlID="btnUpload" />
                    </Triggers>
                </asp:UpdatePanel>
            </span>
        </td>
    </tr>
    <tr>
        <td align="center">
            &nbsp;
        </td>
    </tr>
    <tr>
        <td style="vertical-align: top" align="center">
            <%--<asp:Button ID="btnUpload" Font-Bold="true" DisabledText="Processing..." Visible="false"
                        Text="Upload" BackColor="Maroon" ForeColor="White" runat="server" OnClick="btnUpload_Click" />--%>
            <cc1:ClickOnceButton ID="btnUpload" Font-Bold="true" DisabledText="Processing..."
                Visible="false" Text="Upload" BackColor="Maroon" ForeColor="White" runat="server"
                OnClick="btnUpload_Click" DisableAfterClick="True" />
        </td>
    </tr>
</table>

protected void btn_Click(object sender, EventArgs e)

{

    string strfilename = fp.FileName.ToString();

    if (fp.PostedFile.FileName.Trim().Length != 0)

    {

        binary = new byte[fp.PostedFile.ContentLength];

        binary = fp.FileBytes;

        doc = fp.FileName;

        contenttype = fp.PostedFile.ContentType;


    }

}

Just a sample!!!

+2  A: 

Hai vaishu

FileUpload controls are not compatible with UpdatePanel when they are used to upload files as part of an asynchronous postback.

Just check the AJAX documentation. The FileUpload control is not supported inside an UpdatePanel (http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx):

or

use asp:postbacktrigger instead of asyncpostbacktrigger

<asp:updatepanel runat="server" id="UpdatePanel1">
    <contenttemplate>
        <asp:FileUpload runat="server" id="FileUpload1" />
        <asp:button runat="server" id="ButtonSubmit" text="Postback" />
    </contenttemplate>
    <triggers>
        <asp:postbacktrigger controlid="ButtonSubmit" />
    </triggers>

</asp:updatepanel>

or

use ajax for asynchronous file upload:

http://www.asp.net/(S(fu2l2uzphr2u3u45q2dnez55))/ajax/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx

Pandiya Chendur
what error you got? can specify the exact error type
Pandiya Chendur
No.... It's not working. The file upload control is not taking any values. Dono, whr is the problem!!!
Nila
wait i am going through your code and will let you know
Pandiya Chendur
check you question aspx one ... File upload is outside update panel
Pandiya Chendur
check mine it will work
Pandiya Chendur
"Object Reference not set to an instance of object" This is the error I got. Means, the file upload is empty. That's the problem with both the Control. I tried in that way too.. But, no use!!! Actually, already I'm using update panel in master page.
Nila
Somewhere File Upload control get refresh after the button click.. Dono where!!
Nila
vaishu your aspx code is wrong place file upload inside update panel...
Pandiya Chendur
S.. I changed that too... No use!
Nila
have you placed both the fileupload and button inside the update panel..
Pandiya Chendur
can you paste a screen shot of your error...
Pandiya Chendur
Hi! I found the problem. As I'm using two more buttons in the same page which is the cause of refreshing the file upload control. Now, wat is the solution for this? Plz, tell me!!
Nila
Can you give the names of buttons you use and for what that buttons are used
Pandiya Chendur
Hai vaishu Try to set updateMode="Conditional" for your update panel which contains fileupload control...
Pandiya Chendur
Thanks. But,Sorry. That too not working... :-(
Nila
Vaishu if you dont mind plz send your aspx code and aspx.cs code to [email protected] and i ll let you know what the prob is...
Pandiya Chendur
A: 

you can use AsyncFileUpload file upload control of AJAX, if you need to upload file in update panel.

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx

Edit: you need to register your control with script manager like..

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

I am sure this resolve your problem...

Muhammad Akhtar
Somewhere File upload control is getting refreshed with both the controls. Seems problem is not in the controls, ...
Nila
No. I tried this too. It is not at all working. Still, the file upload is empty..
Nila
A: 

Nothing works for me.. Problem is that I'm using three more buttons in the same page. The other buttons initializing the file upload control. So, when clicking the upload button, the file name is empty. So, I used another page for uploading the word document. Now, it is working.. !! Anyhow, I need the solution for this!! Anyone give me idea!!

Nila
A: 

The reason that the postback trigger is not working in your case is because the FileUpload Control is set to visible=false. If you use display:none instead, the postback trigger will work.

Dennis