Click here to Skip to main content
14,426,138 members
Rate this:
Please Sign up or sign in to 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
   
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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>
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100