I looked through multiple tutorials, but none of it helps. I have page with 4 controls and with tab-panel bootstrap theme. In code-behind of the page I want to save file that I uploaded:
[WebMethod]
public static string UploadFile()
{
try
{
var file = HttpContext.Current.Request.Files["file"];
var filName = Path.GetFileName(file.FileName);
var filePlace = HttpContext.Current.Server.MapPath("Uppladdat") + "\\" + filName;
file.SaveAs(filePlace);
return filePlace;
}
catch (Exception)
{
return "";
}
}
And for ajax request I use that code:
function uploadFileAjax(file) {
var formData = new FormData(file);
// formData.append("file", file);
$.ajax({
url: 'Wizard.aspx/UploadFile',
type: 'POST',
data: formData,
cache: false,
processData: false, // Don't process the files
contentType: false, // Set content type to false as jQuery will tell the server its a query string request
enctype: 'multipart/form-data',
success: function (response) {
console.log(response);
},
error: function (errorThrown) {
// Handle errors here
console.log('ERRORS: ' + errorThrown);
// STOP LOADING SPINNER
}
});
}
It returns to me successful result with page html except one string that I need so much.Also I tried to do some job with update panel, but it refreshes all the page:
<asp:ScriptManager ID="sm1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="col-sm-3">
<input id="uppladdadFil" type="file" name="uppladdadFil" runat="server" />
</div>
<div class="col-sm-4">
<input id="Submit1" class="btn btn-default" type="submit" value="Bifoga" name="Submit1" runat="server" onserverclick="Submit1_ServerClick" />
<input type="hidden" name="HiddenField1" id="HiddenField1" runat="server" />
</div>
<div class="row top10">
<div class="col-sm-6">
<asp:Label ID="lblFilFelmeddelande" CssClass="label label-danger" runat="server" />
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Submit1" />
</Triggers>
</asp:UpdatePanel>
Will be appreciated for any help to resolve that task.
Looks that that link helps. At least I have access to the server side http://www.binaryintellect.net/articles/f2a2f1ee-e18a-416b-893e-883c800f83f4.aspx