ajax.DLL 怎么在前台执行后台的方法?无刷新联动

ajax.DLL 如何在前台执行后台的方法?无刷新联动
ajax.dll已经部署好
前台
JScript code

 function showdept()
  {
Listdepnum()//这样调用行吗?
}





后台
VB.NET code

DropDownList3.Attributes.Add("onClick", "showdept()")

<Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
    Private Sub Listdepnum() '顯示部門
        If DropDownList2.SelectedIndex <> -1 Then
            Dim strSQL As String
            Dim dsResult As New DataSet
            Dim clsDBProcess As New dbprocess.OledbProcess
      strSQL = "select dept_num,dept_nam from DEPT where fac_num='" & DropDownList2.SelectedValue & "'"
            dsResult = clsDBProcess.GetDataSet(Session("Server"), Session("Database"), strSQL)
            DropDownList3.DataSource = dsResult
            DropDownList3.DataTextField = "dept_nam"
            DropDownList3.DataValueField = "dept_num"
            DropDownList3.DataBind()
            DropDownList3.Items.Insert(0, New ListItem("请选择", " "))
        End If
    End Sub





JScript code

以下是其它类同的调用例子
                 function Validata()
            {
         ClassesMaint.Listde(document.all.txtClsnum.value,Validata_Result_CallBack);
            }
           
            function Validata_Result_CallBack(response)
            {
                if (response.value != null)
                {                                   
                var ds = response.value;
                    if(ds != null && typeof(ds) == "object" && ds.tables != null)
                    {           
             for(var i=0; i<ds.tables[0].Rows.length; i++)
                    {
                       document.all.txtCrsnum.value=ds.tables[0].Rows[0].emp_chn_nam;
                      return;
                  }
                    }
                }                
                return
            }            




------解决方案--------------------
直接调用是不可能的
把后台方法写成webservice,再在js里用ajax的方式调用这个webservice,ajax的文档里有例子
如果楼主只要处理dropdownlist的话,可以用ajax的server端extender
------解决方案--------------------
用AjaxPro实现二级联动
在实际asp.net项目中经常会遇到无刷新二级或者N级(N>=2)联动情况,其实N级联动和二级联动的原理都是一样的,实现这种办法有很多,一种是纯脚本实现(动态生成Array数组),一种 是采用微软的Ajax.net中的UpdatePanel来实现,今天我给大家来展示如何采用AjaxPro来实现,相关文章请参考http://blog.csdn.net/zhoufoxcn/archive/2008/01/05/2026908.aspx《AjaxPro与服务器端交互过程中如何传值》一文。
------解决方案--------------------
Page_load里注册了吗?
AjaxPro.Utility.RegisterTypeForAjax(typeof(文件CS的类名)); 
还有JS调用你后台方法时,方法名前还要加类的名称,也就是类名.方法名(这里的类名,就是你注册那个)
------解决方案--------------------
js肯定不能调用后台的方法,用Ajax调用aspx文件,在aspx文件里用page_load调用方法
------解决方案--------------------
web.config中还要添加<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
------解决方案--------------------
应该是方法function吧,不是过程sub。并且方法要为public的,要不生成不了对应的js方法

不知道vb.net的,大概按asp的格式改了下

VB.NET code
<Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _ 
    'Private Sub Listdep(ByVal DropDownList2) '顯示部門 
'=======>
public function Listdep(ByVal DropDownList2) '顯示部門 

        Dim strSQL As String 
        Dim dsResult As New DataSet 
        Dim clsDBProcess As New dbprocess.OledbProcess 
        strSQL = "select dept_num,dept_nam from DEPT where fac_num='" & DropDownList2 & "'" 
        dsResult = clsDBProcess.GetDataSet(Session("Server"), Session("Database"), strSQL) 
'========设置返回值
Listdep=dsResult'不知道vb.net设置对象为返回值是否需要set,如果是asp需要用set
    End function