zoukankan      html  css  js  c++  java
  • 在dotNet中使用AJAX技术的小结

    由于存在免费的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);
                }
             }
    }

  • 相关阅读:
    fastclick插件 导致 input[type="date"] 无法触发问题解决方案
    mysql,命令导入导出表结构或数据
    python使用requests库请求网址时,发生requests.exceptions.SSLError 错误解决办法
    Python使用random.shuffle()随机打乱字典排序
    Zend Studio 配置SVN并导入SVN项目
    ZendStudio调试配置(XDebug)
    PHP会话机制---session的基本使用
    PHP统计当前网站的访问人数,访问信息,被多少次访问。
    题解【luoguP1351 NOIp提高组2014 联合权值】
    题解【luogu P2421 bzoj P1407 [NOI2002]荒岛野人】
  • 原文地址:https://www.cnblogs.com/newwind521/p/483836.html
Copyright © 2011-2022 走看看