Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a aspx page that ask user to enter firstname, last name and upload an image.
I am calling ajax [WebMethod] on a .cs file through jquery to save form data on sql database. However, I am unable to access the asp.net FileUpload control.
How can I upload an image and send its bytes?


Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 5-Apr-15 14:58pm    
Sorry, "I'm unable" is not informative. The uploading of files is demonstrated in huge number of articles and answers.
—SA
F-ES Sitecore 5-Apr-15 15:06pm    
You can't use ajax to upload files. You'll need to use the html5 file api to do this (the browser needs to support html5 though) or use an asynch file upload script. Google for examples of asynch file uploads and you'll find lots of examples.
ZurdoDev 5-Apr-15 21:52pm    
There are many, many examples online. Just google for them and you'll see.
Sudhansu Sekhar Prusty 6-Apr-15 2:55am    
You cant use Asp controls in ajax call. however you can use ajax uploader.
Follow File Upload using jQuery AJAX in ASP.NET Web API[^]

1 solution

Use Ajax update panel..
The Example Below will be useful for you...
Bcos I got the same problem while using FileUpload control.

Example:




    <table>
    <tr>
    <td>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="Button1" runat="server"
                Text="Save" onclick="Button1_Click1" />
        </ContentTemplate>
        <Triggers>
        <asp:PostBackTrigger ControlID="Button1" />
        </Triggers>
        </asp:UpdatePanel>

    </td>
    </tr>
    </table>
</fieldset>
</div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900