Dhanraj
Dhanraj

Reputation: 509

fileupload control not working in the update panel

HI,

fileupload control is inside a grid, When Ajax is not used its s working correctly, so as wen i use a Update panel, am getting a error in uploading my file to thr database, plz help me in this.

Please advice me Dhanraj.S

Upvotes: 2

Views: 7706

Answers (4)

codeandcloud
codeandcloud

Reputation: 55200

Thats because the UpdatePanel does not retain the file inside the asp:FileUpload

Workaround is to set a PostBackTrigger on the button that updates the UpdatePanel

Suppose there is a Button ( lets say UploadFileButton ) that Updates the UpdatePanel. Alter your Panel like this

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:FileUpload ID="TestFileUpload" runat="server" />
        <br />
        <asp:Button ID="UploadFileButton" runat="server" Text="Upload File"/>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="UploadFileButton" />
    </Triggers>
</asp:UpdatePanel>

Upvotes: 3

Pankaj Agarwal
Pankaj Agarwal

Reputation: 11311

You can set Post Back trigger on Submit button. after that you can get image at server side.

for ex.

<Triggers>
<ajax:PostBackTrigger ControlID="btnSubmit" />
</Triggers>

Upvotes: 4

Mayank
Mayank

Reputation: 1631

Probably not what you are looking for but why not use jQuery to upload the file? You can use jQuery Form Plugin to do it. This is the script:

<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.form.js"></script>
<script type="text/javascript">
    $("#myForm").ajaxForm({
        success: function (response) {
            $('#updateDiv').append(response);
        }
    });
</script>

And this is the HTML:

<form id="myForm" action="http://localhost/Default.aspx" method="post"
enctype="multipart/form-data">
<div id="updateDiv" runat="server">
</div>
<div>
    <input type="file" id="filePhoto" name="filePhoto" value="" />
    <input type="submit" value="Upload Photo" />
</div>
</form>

Of course you will have to handle the form submission in your code-behind and send back the appropriate response.

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460108

Have you tried to use the new AsyncFileUpload Control from AjaxControlToolkit 3.5? Here is a step by step guide.

Upvotes: 2

Related Questions