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

时间:2012-03-22 06:26:53

标签: c# ajax

我在使用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 unavailable”。 我可以在内容页面中使用Ajax方法继承主页面中的属性。在母版页中我放置了脚本管理器...请帮助我

1 个答案:

答案 0 :(得分:0)

我找到了问题的解决方案。

在web.config文件中,

添加这些代码行。

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

这将允许Ajax方法。