防止重複提交與驗證控制元件配合使用
為了防止重複提交表單,一般情況下都是在點選按鈕後用javascript把提交按鈕設為disabled。在asp.net 下通常是使用OnClientClick來實現。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><asp:TextBox ID="txt" runat="server">asp:TextBox>
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><asp:TextBox ID="txt" runat="server">asp:TextBox>
<asp:Button ID="btn" runat="server" Text="Button" onclick="btn_Click" OnClientClick="clientclick()" UseSubmitBehavior="false"/>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
$("#").attr("disabled",true);
}
</script>
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
function clientclick()
{
$("#").attr("disabled",true);
}
</script>
但是這種情況下如果使用了驗證控制元件,在驗證控制元件啟用的時候,按鈕同樣會被disabled掉,造成最後無法提交表單。
其實驗證控制元件啟用的時候就是控制對應span的顯示,我們可以用jquery的選擇器得到對應的span的數量,然後再把按鈕重新啟用就可以了。
我的解決辦法:
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><script type="text/javascript">
$(document).ready(function(){
$("#").click(function(){
var span=$("span[id*='Validator']:visible");
if(span.length>0)
{
$(this).attr("disabled",false);
}
});
});
function clientclick()
{
$("#").attr("disabled",true);
}
</script>
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><script type="text/javascript">
$(document).ready(function(){
$("#").click(function(){
var span=$("span[id*='Validator']:visible");
if(span.length>0)
{
$(this).attr("disabled",false);
}
});
});
function clientclick()
{
$("#").attr("disabled",true);
}
</script>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><asp:TextBox ID="txt" runat="server">asp:TextBox>
<asp:Button ID="btn" runat="server" Text="Button" onclick="btn_Click" OnClientClick="clientclick()" UseSubmitBehavior="false"/>
<asp:RequiredFieldValidator ID="Validator" runat="server"
ControlToValidate="txt" ErrorMessage="RequiredFieldValidator">asp:RequiredFieldValidator>
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><asp:TextBox ID="txt" runat="server">asp:TextBox>
<asp:Button ID="btn" runat="server" Text="Button" onclick="btn_Click" OnClientClick="clientclick()" UseSubmitBehavior="false"/>
<asp:RequiredFieldValidator ID="Validator" runat="server"
ControlToValidate="txt" ErrorMessage="RequiredFieldValidator">asp:RequiredFieldValidator>
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->protected void btn_Click(object sender, EventArgs e)
{
//do someing
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->protected void btn_Click(object sender, EventArgs e)
{
//do someing
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-442648/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- js 防止重複提交方案JS
- 前端防止使用者重複提交-js前端JS
- PHP防止使用者重複提交表單PHP
- PHP 防止表單重複提交PHP
- 前端如何防止介面重複提交前端
- 防止表單重複提交的程式碼
- jquery防止重複提交程式碼例項jQuery
- 防止表單重複提交的幾種策略
- 驗證碼機制之驗證碼重複使用
- PHP防止表單重複提交的解決方法PHP
- beego有防止頁面重複提交的功能嗎Go
- Java使用Redis實現分散式鎖來防止重複提交問題JavaRedis分散式
- 13-Jsp防止二次提交(重複提交) 時間戳JS時間戳
- JavaWeb——驗證碼功能解決表單重複提交問題(使用谷歌驗證碼jar包為例)JavaWeb谷歌JAR
- 前臺防止表單重複提交的方法。Jquery、jsjQueryJS
- SpringBoot如何防止重複提交?- Adrian AdendrataSpring Boot
- 專案分享七:客戶端防止表單重複提交客戶端
- PHP透過session判斷防止表單重複提交例項PHPSession
- 如何使POST請求具有冪等性防止重複提交 - mscharhag
- 防止Toast重複提醒AST
- 分散式重複提交分散式
- axios 重複提交iOS
- 防止表單提交按鈕重複點選現象程式碼例項
- 用jquery驗證使用者名稱是否有效或重複jQuery
- 使用檢視配合With Check Option實現複雜校驗
- WinForm MDIParent如何防止重複開啟ORM
- 防止指令碼重複執行方法指令碼
- 驗證控制元件與正規表示式控制元件
- vue+elementUI 複雜表單的驗證、資料提交方案VueUI
- 驗證控制元件控制元件
- ASP.NET驗證控制元件的使用ASP.NET控制元件
- jFinal避免表單重複提交
- 如何防止jQuery物件動畫重複執行jQuery物件動畫
- 關於ajax提交表單,重複提交解決方法
- 使用javascript 實現.net 驗證控制元件功能JavaScript控制元件
- 重複提交,你是如何處理的?
- Spring MVC表單防重複提交SpringMVC
- MVC驗證11-對複雜型別使用jQuery非同步驗證MVC型別jQuery非同步