• 一般删除网页数据和jquery下使用Ajax删除数据的区别


    1. 一般删除网页数据

    就是指用户在点击删除的时候,会跳转到DeleteUser.ashx一般处理程序中,并且通过get传参的方式传递一个id的参数,然后在后台处理

    <a href='DeleteUser.ashx?id={0}

    具体代码如下:

    using CZBK.ItcastProject.Model;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Web;
    
    namespace CZBK.ItcastProject.WebApp
    {
        /// <summary>
        /// UserInfoList 的摘要说明
        /// </summary>
        public class UserInfoList : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/html";
                BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
               List<UserInfo>list= UserInfoService.GetList();
               StringBuilder sb = new StringBuilder();
               foreach (UserInfo userInfo in list)
               {                                                                                 //点击删除跳转的地址                                                
                   sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td><a href='DeleteUser.ashx?id={0}' class='deletes'>删除</a></td><td><a href='ShowDetail.ashx?uid={0}'>详细</a></td><td><a href='ShowEdit.ashx?id={0}'>编辑</a></td></tr>",userInfo.Id,userInfo.UserName,userInfo.UserPass,userInfo.Email,userInfo.RegTime);
               }
                //读取模板文件
               string filePath = context.Request.MapPath("UserInfoList.html");
               string fileCotent = File.ReadAllText(filePath);
               fileCotent = fileCotent.Replace("@tbody",sb.ToString());
               context.Response.Write(fileCotent);
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
    UserInfoList.ashx

    DeleteUser.ashx 相关代码展示如下

    using System;
    using
    System.Collections.Generic; using System.Linq; using System.Web; namespace CZBK.ItcastProject.WebApp { /// <summary> /// DeleteUser 的摘要说明 /// </summary> public class DeleteUser : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int id; // out id 就是指将值赋值给id if (int.TryParse(context.Request.QueryString["id"], out id)) { BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); //如果删除成功 if (UserInfoService.DeleteUserInfo(id)) { //页面重定向 context.Response.Redirect("UserInfoList.ashx"); } else { context.Response.Redirect("Error.html"); } } else { context.Response.Write("参数错误!!"); } } public bool IsReusable { get { return false; } } } }

    2. 通过Ajax删除网页数据

  • 相关阅读:
    updatepanel,linkbutton一点问题
    URL编码处理
    习惯
    style.display,有点问题
    [转]Atlas goes M2.2 or June CTP
    贴代码——从泛型数组中递归删除不符合要求的项
    做好项目,思想要不得
    关于MemoryStream类
    DateTimePicker控件的使用
    Console“自服务”读取文件
  • 原文地址:https://www.cnblogs.com/wangjinya/p/10403808.html
Copyright © 2020-2023  润新知