.net C# 利用Session防重复点击防重复提交

2021-03-31 11:27

阅读:485

标签:button   origin   wpa   ada   public   cli   ade   datetime   --   


   

   

       
       

       

       

       
                    DataKeyNames="Id" DataSourceID="ObjectDataSource1" PageSize="100"
            AllowPaging="True">
           
                                    SortExpression="Id" />
           

       

   


            DeleteMethod="Delete" InsertMethod="Insert"
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
        TypeName="DataSet1TableAdapters.testbeizhuTableAdapter" UpdateMethod="Update">
       
           
       

       
           
       

   
   

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Session["fangchongfu"] = DateTime.Now.ToString();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        DateTime time1 = DateTime.Now;
        DateTime lastTime = Convert.ToDateTime(Session["fangchongfu"].ToString());
        TimeSpan ts = time1 - lastTime;
        if (10 > ts.TotalSeconds)//小于10秒,则判定为重复提交
        {
            return;
        }
        Session["fangchongfu"] = DateTime.Now.ToString();

        //利用插入和显示数据量特别大的一张表来模拟网络卡的情况
        DataSet1TableAdapters.testbeizhuTableAdapter bzAda = new DataSet1TableAdapters.testbeizhuTableAdapter();
        bzAda.InsertQuery();

        GridView1.DataSourceID = "ObjectDataSource1";
        GridView1.DataBind();

        DateTime time2 = DateTime.Now;

        Label1.Text = "用时:" + ts.TotalSeconds.ToString() + ",当前时间:" + DateTime.Now.ToString();
    }
}

.net C# 利用Session防重复点击防重复提交

标签:button   origin   wpa   ada   public   cli   ade   datetime   --   

原文地址:https://www.cnblogs.com/yubufan/p/9260682.html


评论


亲,登录后才可以留言!