国产探花免费观看_亚洲丰满少妇自慰呻吟_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秒鐘按鈕才能點擊。即頁面回發一后按鈕才能用。這樣可以有效的防止用戶多次點擊按鈕,造成多次提交!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河东区| 乌苏市| 枣庄市| 额敏县| 辽中县| 建宁县| 视频| 自贡市| 政和县| 四会市| 磐安县| 瓮安县| 伊宁市| 和田县| 呼伦贝尔市| 多伦县| 武宁县| 古交市| 滦平县| 温宿县| 双城市| 武城县| 丽江市| 鹤峰县| 西平县| 中超| 瑞金市| 东莞市| 吉木萨尔县| 察隅县| 武威市| 兴隆县| 镇原县| 洱源县| 玉屏| 石屏县| 阳朔县| 高台县| 会昌县| 汉源县| 八宿县|