C# 如何在内容页中使用ajax方法

C# 如何在内容页中使用ajax方法,c#,ajax,C#,Ajax,我在使用Ajax方法时遇到问题。我有一个母版页和一个内容页。我想在内容页中使用Ajax方法。为此 在cs页面中的页面加载: Ajax.Utility.RegisterTypeForAjax(typeof(testcontent)); 我添加了这个,因为我的内容页面名是testcontent 这是我在cs页面中的方法: [Ajax.AjaxMethod()] public int Getdatabyid(int id) { int count = 0 ;

我在使用Ajax方法时遇到问题。我有一个母版页和一个内容页。我想在内容页中使用Ajax方法。为此

在cs页面中的页面加载:

Ajax.Utility.RegisterTypeForAjax(typeof(testcontent));
我添加了这个,因为我的内容页面名是testcontent

这是我在cs页面中的方法:

 [Ajax.AjaxMethod()]
  public int Getdatabyid(int id)
  {
        int count  = 0 ;
       //getting the id and basing on that processing the data and assigning to count
        return count;
  }
在我的aspx页面中:

function getdata(value)
{
 var id = value;
  var count = testcontent.Getdatabyid(id);
}
但是我得到了错误“testcontent不可用”。
我可以在继承母版页属性的内容页中使用Ajax方法吗?在母版页中,我放置了脚本管理器…请帮助我解决问题。

我找到了问题的解决方案

在web.config文件中

添加这些代码行

 <system.web>
   <httpHandlers>
     <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory,Ajax"/>
   </httpHandlers>
 </system.web>


这将允许使用Ajax方法。

我找到了问题的解决方案

在web.config文件中

添加这些代码行

 <system.web>
   <httpHandlers>
     <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory,Ajax"/>
   </httpHandlers>
 </system.web>

这将允许使用Ajax方法