国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET 多次提交的解決辦法2

2024-07-10 12:39:19
字體:
來源:轉載
供稿:網友
例如:
protected void Page_Load(object sender, EventArgs e)
{
//.net1.1
Button1.Attributes.Add("onclick", "this.disabled=true;" + this.GetPostBackEventReference(this.Button1));
//.net 2.0以上
Button1.Attributes.Add("onclick", "this.disabled=true;" + this.ClientScript.GetPostBackEventReference(Button1, ""));
}
為了測試,我們可以建立一個頁面,加入一個btnAdd按鈕
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddAndEditUser.aspx.cs" Inherits="AddUser" %><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>添加和編輯頁面示例</title>
</head>
<body>
<form id="frmMain" runat="server">
<asp:Button ID="btnAdd" runat="server" CssClass="INPUT-BUTTON-Save" OnClick="btnAdd_Click">
</asp:Button>
</form>
</body>
</html>
/*----------------------------------------------------------------
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class AddUser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
btnAdd.Attributes.Add("onclick", "this.disabled=true;" + this.ClientScript.GetPostBackEventReference(btnAdd, ""));
}
protected void btnAdd_Click(object sender, EventArgs e)
{
//模擬網絡擁塞5秒鐘
System.Threading.Thread.Sleep(5000);
}
}
可見當點擊了按鈕,需要等5秒鐘按鈕才能點擊。即頁面回發一后按鈕才能用。這樣可以有效的防止用戶多次點擊按鈕,造成多次提交!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 横峰县| 洞头县| 永靖县| 五寨县| 林甸县| 武安市| 韩城市| 文登市| 西吉县| 五原县| 巴林右旗| 成武县| 江安县| 哈巴河县| 桐梓县| 安徽省| 浮梁县| 蕲春县| 兰考县| 灵石县| 青河县| 通州市| 铅山县| 宣化县| 昌宁县| 敦化市| 民县| 华宁县| 长宁区| 孟连| 东城区| 屯门区| 积石山| 高青县| 永和县| 海盐县| 班玛县| 西乡县| 临泽县| 南丹县| 浦县|