蓝狐的技术思考 BlueFox Thinking in Tech...
交流,分享,探讨技术...... Communication, Sharing, and Discussion about Technology.....

导航

 

由于存在免费的AJAX引擎可在DotNet中使用,使得在这一炙手可热的技术变得不在遥远。现在对应用较普遍的AjaxPro.dll和Ajax.dll的使用步骤用一示例进行以下小结:
1.在Web.config文件中添加配置信息。
<system.web>
   <globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
    <httpHandlers>
      <add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
    </httpHandlers>
   ...
</system.web>
2.在PageLoad事件中注册后台代码类:
public partial class MeetingManage_NewMeeting : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(MeetingManage_NewMeeting));
           ...
    }
...
}
3.在后台代码类中注册欲在客户端调用的方法:注意该方法一定要声明为public,否则若用protected或private均不能在前台访问。
    //删除会议资料附件
    [AjaxPro.AjaxMethod]
    public string DelMeetingData(string filePath)
    {
        try
        {
            if (filePath != "")
                File.Delete(Server.MapPath(filePath));
            return "true";
        }
        catch (Exception ex)
        {
            return "false";
        }
    }

4.在页面文件中调用后台代码类中的方法。
    //删除上传文件
    function DelFile(lstID)
    {
        var lstFile=document.getElementById(lstID);
        for(var i=0;i<lstFile.options.length;i++)
         {
            if(lstFile.options[i].selected)
            {
                var strValue=lstFile.options[i].value;
                var strArray=strValue.split(",");
                var strDelFile=strArray[2]+strArray[0];
                var result=MeetingManage_NewMeeting.DelMeetingData(strDelFile).value;
                if (result=="true")
                    alert("文件删除成功!");
                lstFile.options.remove(i);
            }
         }
}

posted on 2006-08-23 00:07  蓝狐  阅读(487)  评论(6编辑  收藏  举报