omega
omega

Reputation: 43833

How to use jquery ajax with c#?

I am trying to get my asp.net solution to work with jquery ajax. I am using this example:

http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

I have this so far, but it's giving me namespace errors about it not being defined. Page and WebMethod is not defined...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PDFLibrary.PDFLibrary
{
    public partial class SaveStructure : Page
    {
        [WebMethod]
        public static string GetDate()
        {
            return DateTime.Now.ToString();
        }
    }
}

Does anyone know how to fix this?

Thanks

Upvotes: 2

Views: 271

Answers (2)

Subhash Sasidharakurup
Subhash Sasidharakurup

Reputation: 368

You need to add [System.Web.Script.Services.ScriptService] and [WebService(Namespace = "Your namespace(eg http://tempuri.org/)")]

Upvotes: 0

Abe Miessler
Abe Miessler

Reputation: 85036

Visual Studio actually has a nice way of including missing namespaces. Right click on WebMethod (or whatever is not recognized), mouse over the submenu that says Resolve and then select using System.Whatever which will be your missing namespace.

This is a nice feature that allows you to include namespaces without having to look them up.

Upvotes: 5

Related Questions