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
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>
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>
Have you tried to use the new AsyncFileUpload Control from AjaxControlToolkit 3.5? Here is a step by step guide.
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.
精彩评论