方法:
[Ajax.AjaxMethod()]
public void hitacc(string nid)
{
int dnid=Convert.ToInt32(nid);
SqlCommand SqlCmd = new SqlCommand();
SqlCmd.Connection = new SqlConnection(ConfigurationSettings.AppSettings["ConnString"]);
SqlCmd.CommandText = "update news set hit=hit+1 where nid="+dnid;
SqlCmd.CommandType = CommandType.Text;
SqlCmd.Connection.Open();
SqlCmd.ExecuteNonQuery();
SqlCmd.Connection.Close();
}js代码:
<script language=javascript>
function abc(e)
{
    hitacc(e.id.value);
   
}
</script>
用js的代码:
<a id=<%# DataBinder.Eval(Container.DataItem, "nid") %> onclick="abc(this);"/a>数据库中没有反应,点击数没有加1啊。

解决方案 »

  1.   

    cs中也加了引用
    Ajax.Utility.RegisterTypeForAjax(typeof(SFAjaxMethod));
      

  2.   

    hitacc(e.id.value);要改成: 命名空间.类名.hitacc(e.id.value);
      

  3.   

    改了加了类名,SFAjaxMethod。hitacc(e.id.value);
    提示错误是 'undefined'为空或不是对象
      

  4.   

    js代码:
    <script language=javascript>
    function abc(e)
    {
        hitacc(e.id);
       
    }
    </script>试试
      

  5.   

    其实我的问题很简单,就是在<a id="数据库中新闻的id号"></a> 根据onclick事件触发数据库加一,统计点击数,刚才仔细观察了下,发现是
    <a id=<%# DataBinder.Eval(Container.DataItem, "nid") %> onclick="abc(this);"/a>
    中的id的值没有加引号,还有数据库中hit的初始值不能为空,要是个具体的数字才能正确加一,
    为了这个问题搞了半天啊。
    谢谢大家捧场了!