how to go to call method inside asp page from js file

Posted by Shanky11 under jQuery on 7/9/2014 | Points: 10 | Views : 565 | Status : [Member] | Replies : 8
i am uisng this code
<button onclick="javascript: UploadPainImage();return false;">Save Edited Image</button>

.js file------------
function UploadPainImage() {

// generate the image data for PainIamge

var Picpain = document.getElementById("myCanvas1").toDataURL("image/png");
Picpain = Picpain.replace(/^data:image\/(png|jpg);base64,/, "")
//

// Sending the image data to Server
$.ajax({
type: 'POST',
url: 'SaveRomInspectionImg.aspx/UploadPainImage',

data: '{ "imageData1" : "' + Picpain + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Done,Pain Image Uploaded .");
}
});
}

--------------------------------------------asp page code
using System;
using System.Web;
using System.IO;
using System.Web.Script.Services;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

[ScriptService]
public partial class Doctor_SaveRomInspectionImg : System.Web.UI.Page
{
//public static string patientid;
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod()]
public static void UploadPainImage(string imageData1)
{
string Pic_Path = HttpContext.Current.Server.MapPath("RomInspectionImg.png");
using (FileStream fs = new FileStream(Pic_Path, FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(imageData1);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "sp_updateRomInspectimage";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@pid", GlobalVariable.patid));
cmd.Parameters.Add(new SqlParameter("@painimg", data));
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
bw.Write(data);
bw.Close();
}
}
}

}





Responses

Posted by: Vuyiswamb on: 7/10/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
What is the Problem ?

Thank you for posting at Dotnetfunda
[Administrator]

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 7/10/2014 [Member] Starter | Points: 25

Up
0
Down
<button onclick="javascript: UploadPainImage();return false;">Save Edited Image</button>
when i click this button its not going on asp page i.e .cs file where i defined web method

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/11/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Can i see the definition of your Script manager. if its not like this

<asp:ScriptManager ID="ScriptManager" runat="server"
EnablePageMethods="true" />

then change it to that

Thank you for posting at Dotnetfunda
[Administrator]

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 7/11/2014 [Member] Starter | Points: 25

Up
0
Down
when i change the image its working fine
button click call this function i used a alert in this script its showing that msg but the method UploadPainImage which is defined in url not working
function UploadPainImage() {

// generate the image data for PainIamge
debugger;
var Picpain = document.getElementById("myCanvas1").toDataURL("image/png");
Picpain = Picpain.replace(/^data:image\/(png|jpg);base64,/, "")
//


// Sending the image data to Server
$.ajax({
type: 'POST',
url:'SaveRomInspectionImg.aspx/UploadPainImage',
data: '{ "imageData1" : "' + Picpain + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Done,Pain Image Uploaded .");
}
});


}

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/11/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
Did you implement what i sent you and again

What do you mean "when i change the image its working fine"

Thank you for posting at Dotnetfunda
[Administrator]

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 7/11/2014 [Member] Starter | Points: 25

Up
0
Down
the same thing i am using on this page thats working fine the image i am using in that when i use that image its working fine
so whats the reason behind it by changing image its working fine
image foramt is jpg both.
one more thing i am using this on canvas
when Rom_Combined is used its working fine but when i tried test_pain image its not working
 Download source file

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/11/2014 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
if you press F12 do you see an Error when you use the image that gives you an error. Press F12 and go to Console

Thank you for posting at Dotnetfunda
[Administrator]

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shanky11 on: 7/11/2014 [Member] Starter | Points: 25

Up
0
Down
no error is coming it doesnot go to my page where web method is defined

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response