Click here to Skip to main content
15,606,569 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a webservice"Default.asmx" code behind file in App-Code folder."Default.cs" While button click i want to display Webmethod string from webservice.But not working.How o type url for app_code webservice file?

What I have tried:

[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
public class _Default : System.Web.Services.WebService {

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);

    SqlConnection conRecipes = new SqlConnection(ConfigurationManager.ConnectionStrings["constrRecipes"].ConnectionString);

    public _Default () {


        //Uncomment the following line if using designed components 
    public string AddNominations()
        return "Nomination Added Successfully";

Ajax call
function CallService() {

            type: "POST",
            url: "_Default.asmx/AddNominations",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: Success,
            error: Error
    function Success(data, status) {

    function Error(request, status, error) {
Updated 5-Apr-17 18:43pm
Karthik_Mahalingam 5-Apr-17 8:49am    
what is the error message?
GrpSMK 5-Apr-17 9:52am    
Button clicked,no messeges displayed
Karthik_Mahalingam 5-Apr-17 9:54am    
check in chrome console window, if there is any error
GrpSMK 5-Apr-17 9:53am    
when i create webservice ,class file automatically created in app_code folder..whats the use ?how to call AddNominations in ajax call?
ZurdoDev 5-Apr-17 9:57am    
2 things.
1. You have an underscore in the javascript for the file name
2. Put a breakpoint in your success and error functions and see what is happening.

Make the File name uniform

url: "YourWebService.asmx/AddNominations",
Share this answer
function CallService() {

type: "POST",
contentType: "application/json; charset=utf-8",
url: "_Default.asmx/AddNominations",
dataType: "json",
success: function (data) {
error: function (x, e) {

Check this it may help you.
Share this answer

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

  Print Answers RSS

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