Galslubbasex
New Member
I have an aspx page containing a jquery/ajax call to my .cs where a stored procedure is executed. The stored procedure returns an int value that I would like to pass back to the orginating form without performing a page refresh.So far the ajax call is working great. The stored procedure is updating my sql db. I'm also able to put the outputted int from the stored procedure in a variable local to the .cs page. The problem arises when I attempt to store that variable into a hidden field on the aspx page. The Jquery/Ajax api states that one of the three argumests passed to the success function is "The data returned from the server". thats great but I don't understand how to tell the ajax "this is the variable I want to return into my success function". below is my summerized .aspx code:
\[code\] var dataToSend = { somedata: $("#somefield").val(), MethodName: 'myMethod'}; var options = { url: '<%=ResolveUrl("~/mypage.aspx") %>', async: false, data: dataToSend, dataType: 'text', type: 'POST', success: function (result) { // I would like to store the returned data // into a hidden field on the client side (this aspx page) alert(result); //currently the result only shows the aspx/html of my page.\[/code\]Here is summerized version of my .cs code behind:\[code\]using System;using System.Collections.Generic;using System.Data; //using System.Data.SqlClient; //using System.Data.SqlTypes; //using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.Services;public partial class _Default : System.Web.UI.Page{ public int passmetoaspx; private string strsomedata; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Request.Form["MethodName"] == "myMethod") { updateDatabase(); return; } } } protected void updateDatabase() { try { // create string variables for form data somedata = http://stackoverflow.com/questions/15713630/Request.Form["somedata"].ToString(); using (SqlConnection sconn = new SqlConnection(myconnstring)) { using (SqlCommand scmd = new SqlCommand("mystored_procedure", sconn)) { scmd.CommandType = CommandType.StoredProcedure; scmd.Parameters.Add("@somedata", SqlDbType.VarChar).Value = http://stackoverflow.com/questions/15713630/strsomedata; scmd.Parameters.Add("@sndtoASPXpage", SqlDbType.Int); scmd.Parameters["@sndtoASPXpage"].Direction = ParameterDirection.Output; sconn.Open(); scmd.ExecuteScalar(); int returnUID; passmetoASPXpage = int.Parse(scmd.Parameters["@sendtoASPXpage"].Value.ToString()); } } } catch (Exception er) { }}\[/code\]Please try to point me in the right direction here. Thank you.
\[code\] var dataToSend = { somedata: $("#somefield").val(), MethodName: 'myMethod'}; var options = { url: '<%=ResolveUrl("~/mypage.aspx") %>', async: false, data: dataToSend, dataType: 'text', type: 'POST', success: function (result) { // I would like to store the returned data // into a hidden field on the client side (this aspx page) alert(result); //currently the result only shows the aspx/html of my page.\[/code\]Here is summerized version of my .cs code behind:\[code\]using System;using System.Collections.Generic;using System.Data; //using System.Data.SqlClient; //using System.Data.SqlTypes; //using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.Services;public partial class _Default : System.Web.UI.Page{ public int passmetoaspx; private string strsomedata; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Request.Form["MethodName"] == "myMethod") { updateDatabase(); return; } } } protected void updateDatabase() { try { // create string variables for form data somedata = http://stackoverflow.com/questions/15713630/Request.Form["somedata"].ToString(); using (SqlConnection sconn = new SqlConnection(myconnstring)) { using (SqlCommand scmd = new SqlCommand("mystored_procedure", sconn)) { scmd.CommandType = CommandType.StoredProcedure; scmd.Parameters.Add("@somedata", SqlDbType.VarChar).Value = http://stackoverflow.com/questions/15713630/strsomedata; scmd.Parameters.Add("@sndtoASPXpage", SqlDbType.Int); scmd.Parameters["@sndtoASPXpage"].Direction = ParameterDirection.Output; sconn.Open(); scmd.ExecuteScalar(); int returnUID; passmetoASPXpage = int.Parse(scmd.Parameters["@sendtoASPXpage"].Value.ToString()); } } } catch (Exception er) { }}\[/code\]Please try to point me in the right direction here. Thank you.