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

首頁 > 編程 > .NET > 正文

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

2024-07-10 13:21:03
字體:
來源:轉載
供稿:網友
例如:
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 runat="server">
<asp:Button runat="server" CssClass="INPUT-BUTTON-Save">
</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秒鐘按鈕才能點擊。即頁面回發一后按鈕才能用。這樣可以有效的防止用戶多次點擊按鈕,造成多次提交!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 林甸县| 淄博市| 宜川县| 曲周县| 内江市| 勐海县| 化州市| 来安县| 山东省| 聂拉木县| 辽中县| 洛隆县| 贺兰县| 都安| 宁夏| 页游| 西城区| 阜康市| 合作市| 滨州市| 东丽区| 云阳县| 霍山县| 云南省| 长沙县| 莫力| 普兰店市| 奈曼旗| 聂荣县| 中西区| 天津市| 永宁县| 德昌县| 大邑县| 巫溪县| 乌拉特后旗| 会东县| 迁西县| 安乡县| 太仆寺旗| 会宁县|