我的项目中使用了ajaxpro是为了加载页面时,显示“请稍等……”,但在后台的方法中绑定gridview去不显示数据。这是我的代码
页面
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
      <script language="JavaScript" type="text/JavaScript">   
  <!--   
  function   Working()   {   //v3.0   \
  
  var a=_Default.aaa(aa)
    alert(a);
  }   
  function aa()
  {
         document.getElementById("div2").style.display="none";
         document.getElementById("div1").style.display="";
  }
  //-->   
    </script>
</head>
<body onload="Working()">
    <form id="form1" runat="server"><div id="div2" runat="server" style="z-index: 1; left: 430px; position: absolute;
        top: 245px;">
        <input type="image" src="busy.gif" />
        &nbsp;&nbsp;请稍等……
    </div>
    <div id="div1" >
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
            <Columns>
                <asp:BoundField DataField="name" HeaderText="name" />
                <asp:BoundField DataField="sex" HeaderText="sex" />
                <asp:BoundField DataField="4" HeaderText="4" />
                <asp:BoundField DataField="year4" HeaderText="year4" />
            </Columns>
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList></div>
    </form>
</body>
</html>
后台
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax
         (typeof(_Default));
        if (!IsPostBack)
        {
          //  aaa();
        }    }    [AjaxPro.AjaxMethod]
    public string aaa()
    {
        DataSet ds = new DataSet();
        try
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
            SqlDataAdapter da = new SqlDataAdapter("select top 10 * from tblperson", con);
          
            da.Fill(ds, "tblperson");
            this.DropDownList1.DataTextField = "name";
            this.DropDownList1.DataValueField = "name";
            this.DropDownList1.DataSource = ds;
            this.DropDownList1.DataBind();            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }
        catch (Exception e){            Response.Write(e);
        }
        return "123";
    }
   
}

解决方案 »

  1.   

    public string aaa() 
    这方法里应该有参数吧?
      

  2.   

    两个错误
    一、using没有引用ajaxpro
    二、你不能在后台用ajax方法对服务器控件进行操作,那是无效的,你应该是返回一个结果集(如DataSet)给前台用js操作
    按你上面的操作,你最后的"123"都返回不到前台的
      

  3.   

    在.NET下的应用主要是三步骤:
    >> 在项目中引用AjaxPro.dll
    >> 首先是web.config里面的配置信息
    >> 然后在页面中Using AjaxPro1.Web.config文件中加上如下配置:
    <httpHandlers> 
    <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/> 
    </httpHandlers>2. 打开后台代码,在Page_Load方法体内加上如下代码, 
    AjaxPro.Utility.RegisterTypeForAjax(typeof(所在类的类名));
    3.写类方法
    [AjaxPro.AjaxMethod]
    Public int add(int a,int b)
    {
    a = a+b;
    return  a;
    }
    4.在web端页面中直接使用
    var result =    [名称空间].[类名]. add (1,2);Ok了,就这么简单!!
      

  4.   

    返回JS后在前台怎么操作?我的"123"为什么返回不到前台?
    没有引用ajaxpro为什么能照常使用呢?
      

  5.   

    但[AjaxPro.AjaxMethod]下的方法不能操作服务器控件