i am using ajax jquery and asp.net webmethods as you can see in code.now i can get controls values to save data in database.now the issue is i can not get file data to upload to server.i want to save image in database sqlserver.
ajax uses XmlHttpRequest, which does not support file uploads (at least in IE). the standard work around is to use a form in an iframe to do the file post.
How i ll use a form in an iframe to do the file post?i am saving company name and location on ajax,now i want to save logo too...can i use this in parralel or what sort of code ll suite?any idea or code flow?
How i ll use a form in an iframe to do the file post?i am saving company name and location on ajax,now i want to save logo too...can i use this in parralel or what sort of code ll suite?any idea or code flow?
1)i want to get the posted file value on parent files as i do have alot of other values to save with.can i get this ifram value/posted file value of my parent page?
For first issue you can save the file in folder and add the saved file location in session and use it in the parent page. For second issue you have to modify your css accordingly.
Thanks & Regards
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
shafiqkr
Member
454 Points
372 Posts
Posting Forms in Jquery and asp.net
Nov 23, 2011 08:41 AM|LINK
I want to get file content.here is my code
<div>$("#btnsave").click(function () {
$.ajax({
type: "POST",
url: "CompanyDetail.aspx/SaveCompany",
data: "{'logo':'" + $("#file").val()+ "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#Result").text(msg.d);
}
}); });
here file is the field/control name to browse images.
on aspx.cs file
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static string SaveCompany(string logo)
{
Company objCmp = new Company();
objCmp.Logo = logo;
objCmp.insertCompany();
}
can i get filecontents to save as binary in sqlserver?
</div>nilsan
All-Star
16878 Points
3700 Posts
Re: Posting Forms in Jquery and asp.net
Nov 23, 2011 08:58 AM|LINK
Could you elaborate more on this?
Blog | Get your forum question answered | Microsoft Community Contributor 2011
asteranup
All-Star
30184 Points
4906 Posts
Re: Posting Forms in Jquery and asp.net
Nov 23, 2011 09:15 AM|LINK
Hi,
This can not be done using jquery like this. You can use some available plugins like-
http://pixelcone.com/jquery/ajax-file-upload-script/
http://www.phpletter.com/Demo/AjaxFileUpload-Demo/
And you can save and retrive image from database like-
http://www.codeproject.com/KB/database/UploadPicturesSQLServer.aspx
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
shafiqkr
Member
454 Points
372 Posts
Re: Posting Forms in Jquery and asp.net
Nov 23, 2011 10:54 AM|LINK
i am using ajax jquery and asp.net webmethods as you can see in code.now i can get controls values to save data in database.now the issue is i can not get file data to upload to server.i want to save image in database sqlserver.
@asteranup:
i do not want to go to web page method as you prefer me a link.i want to use webmethods as i mentioned in my code
bruce (sqlwo...
All-Star
36822 Points
5441 Posts
Re: Posting Forms in Jquery and asp.net
Nov 23, 2011 03:05 PM|LINK
ajax uses XmlHttpRequest, which does not support file uploads (at least in IE). the standard work around is to use a form in an iframe to do the file post.
shafiqkr
Member
454 Points
372 Posts
Re: Posting Forms in Jquery and asp.net
Nov 24, 2011 08:44 AM|LINK
Bruce:
How i ll use a form in an iframe to do the file post?i am saving company name and location on ajax,now i want to save logo too...can i use this in parralel or what sort of code ll suite?any idea or code flow?
asteranup
All-Star
30184 Points
4906 Posts
Re: Posting Forms in Jquery and asp.net
Nov 25, 2011 04:16 AM|LINK
Hi,
You can try this-
http://forums.asp.net/p/1710264/4553814.aspx/1?Re+Upload+using+IFRAME+and+Jquery+
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Posting Forms in Jquery and asp.net
Nov 26, 2011 12:52 PM|LINK
For uploading binary files you will have to use the jQuery Fileupload plugin
Refer the following
http://www.aspforums.net/Threads/107889/Upload-File-using-jQuery-AJAX-ASPNet/
Contact me
shafiqkr
Member
454 Points
372 Posts
Re: Posting Forms in Jquery and asp.net
Nov 27, 2011 12:15 PM|LINK
@asteranup:
Nice methods at your this link
http://forums.asp.net/p/1710264/4553814.aspx/1?Re+Upload+using+IFRAME+and+Jquery+
But still i have two issue with this.
1)i want to get the posted file value on parent files as i do have alot of other values to save with.can i get this ifram value/posted file value of my parent page?
2)when i use this line
<iframe id="frameUpload" name="frameUpload" style="display: none" src="FileUpload3.aspx" />
this creates problems with my design.how i can hide it and disable its css etc?
asteranup
All-Star
30184 Points
4906 Posts
Re: Posting Forms in Jquery and asp.net
Nov 28, 2011 04:30 AM|LINK
Hi,
For first issue you can save the file in folder and add the saved file location in session and use it in the parent page. For second issue you have to modify your css accordingly.
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog