I'm using jquery, ajax, & .net to call a method. I see lots of examples on the net saying to put [Webmethod] above the method but I'm keeping getting the error the type or namespace name 'webmethod' could not be found. I have put "using System.Web.Services;" at the top. What else needs to be done?
using System;
using System.Collections.Generic;
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
{
[WebMethod]
public static string GetDate()
{
return DateTime.Now.ToString();
}
}
The WebMethod attribute is added to each method we want to expose as a Web Service. ASP.NET makes it possible to map traditional methods to Web Service operations through the System. Web. Services. WebMethod attribute and it supports a number of properties that control the behavior of the methods.
The WebMethod attribute has properties that are used to configure the behavior of the specific web method. Here is the syntax: [WebMethod(PropertyName=value)] PropertyName is a valid property accepted by the WebMethod attribute (these are described below), and value is the value to be assigned to that property.
The WebMethod will be called using ASP.Net AJAX PageMethods. ASP.Net AJAX ScriptManager allows you to call Server Side ASP.net methods from client side without any PostBack using PageMethods. Actually it is an AJAX call to the server but it allows us to call the method or function defined server side.
Add a reference to System.Web.Services.dll
in your project.
It is most likely missing for you to be getting this error because you already have the correct using
statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With