Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a ajax post method in asp.net see below the code

$('#Button1').click(function () {
$.ajax({
url: "AjaxFunctionality.aspx/GetElemtData",
data: { helpTextKey: $('txtPlantId').val() },
method: 'post',
dataType: 'xml',
sucess: function (response, status, xhr) {
var resp = $(response);
alert(resp);
}

});

});
});
by using post method i have to call C# method see method below:

public string GetElemtData(string obj)
{
//String obj = Request["helpTextKey"];
String returnValue = string.Empty;
String connectionstring = ConfigurationManager.ConnectionStrings["ECSConnectionString"].ConnectionString;

using (SqlConnection con = new SqlConnection(connectionstring))
{
SqlCommand cmd = new SqlCommand("select top 1 * from Carriers where plantid='" + obj + "'", con);
con.Open();
SqlDataReader dr= cmd.ExecuteReader();
while(dr.Read())
{
returnValue = dr[3].ToString();
}
con.Close();
dr.Close();
}
return returnValue;
}

I have tried several time to calling the method but but i couldn't be called. please help on this how to approach.
Posted
Comments

1 solution

You have reinvented WebAPI :)
But you know what, you can have both: http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/using-web-api-with-aspnet-web-forms[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900