源码如下
  [AjaxPro.AjaxMethod]
    public string result()
    {
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();        if (HttpContext.Current.Cache["result"] != null)
        {
            ds = (DataSet)HttpContext.Current.Cache["result"];
            dt.Rows[0]["username"] = txtUserName.Text;
            dt.Rows[0]["txtPass"] = txtPass.Text;
            ds.Tables.Add(dt);
            HttpContext.Current.Cache["result"]=ds;
        }
        else
        {
            dt.Columns.Add("username", typeof(System.String));
            dt.Columns.Add("pass", typeof(System.String));
            dt.Rows[0]["username"] = txtUserName.Text;
            dt.Rows[0]["txtPass"] = txtPass.Text;
            ds.Tables.Add(dt);
            HttpContext.Current.Cache["result"] = ds;
        }
        return ds.GetXml();
    }

解决方案 »

  1.   

    Ajax调用result()这个方法时,显示的是NUL值
      

  2.   

    cache为null吗?!
      

  3.   

    不是的,Cache有值,但是AJAX调用到dt.Rows[0]["username"]   =   txtUserName.Text; 就返回NULL了
      

  4.   


    //                        dt.Rows[0]["username"]   =   txtUserName.Text;
      //                      dt.Rows[0]["txtPass"]   =   txtPass.Text; 
    //改为下面的试试
            DataRow row = dt.NewRow();
            row["username"] = txtUserName.Text;
            row["txtPass"] = txtPass.Text;
            dt.Rows.Add(row);