日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

防止ASP.NET按钮多次提交的办法

發(fā)布時(shí)間:2023/12/10 asp.net 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 防止ASP.NET按钮多次提交的办法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
方法一
<asp:Button ID="btnSumbit" runat="server" UseSubmitBehavior="false" OnClientClick="this.value='Sumbit';this.disabled=true; " Text="Sumbit" OnClick="btnSumbit_Click" />

方法二
?1<html?xmlns="http://www.w3.org/1999/xhtml">
?2<head?runat="server">
?3????<title>禁止多次提交網(wǎng)頁測試</title>
?4????<style?type="text/css">
?5????.disable
?6????{}{
?7????????border-style:none;?
?8????????border-width:?thin;?
?9????????background-color:Transparent;?
10????????color:?#CCCCCC;?
11????????cursor:wait;
12????}

13????
</style>
14????<script?type="text/javascript"?language="javascript">
15????function?DisableButton()
16????{
17????????document.getElementById("Button2").className??=?"disable";
18????????document.getElementById("Button2").value?=?'正在提交.';
19????????document.getElementById("Button2").onclick=Function("return?false;");
20????????return?true;
21????}

22????document.onkeydown=mykeydown;???
23????function???mykeydown()
24????{???
25????????if(event.keyCode==116)?//屏蔽F5刷新鍵???
26????????{???
27????????????window.event.keyCode=0;???
28????????????return???false;???
29????????}
???
30????}
???
31????
</script>
32
33</head>
34<body>
35????<form?id="form1"?runat="server">
36????<div>
37????????輸入一些內(nèi)容<asp:TextBox?ID="TextBox1"?runat="server"></asp:TextBox>
38????????<br?/>
39????????<asp:ListBox?ID="ListBox1"?runat="server"?Height="77px"?Width="332px">
40????</asp:ListBox><br?/>
41????????<asp:Button?ID="Button2"?runat="server"?Text="OK"?Width="77px"
42????????????onclick="Button2_Click"?/>
43????</div>
44????
45????</form>
46</body>
47</html>
48
服務(wù)器端代碼,故意讓其延時(shí)等待3秒后再輸入,以模擬數(shù)據(jù)庫操作等慢速動(dòng)作。
?1public?partial?class?Default2?:?System.Web.UI.Page
?2{
?3????static?public?int?count?=?0;
?4????protected?void?Page_Load(object?sender,?EventArgs?e)
?5????{
?6????????if?(!IsPostBack)
?7????????{
?8????????????Button2.Attributes.Add("onclick",?"return?DisableButton();");
?9????????}

10????}

11
12????protected?void?Button2_Click(object?sender,?EventArgs?e)
13????{
14????????if?(TextBox1.Text?!=?string.Empty)
15????????{
16????????????System.Threading.Thread.Sleep(3000);
17????????????count++;
18????????????ListBox1.Items.Add(new?ListItem("Hello?"+TextBox1.Text?+?"??這是你第"?+?count.ToString()?+?"次點(diǎn)擊???"?+?DateTime.Now.ToString()));
19????????????TextBox1.Text?=?"";
20????????}

21????}

22}

轉(zhuǎn)載于:https://www.cnblogs.com/wayne-ivan/archive/2008/07/18/1246022.html

總結(jié)

以上是生活随笔為你收集整理的防止ASP.NET按钮多次提交的办法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。