無效的...他是在一個過程中,沒有POST到客戶端的,這個時候還是可以點擊的. 其實很簡單,用JAVASCRIPT來實現啊, 第一種方法:在onclick事件中綁定把自己disabled 前端頁面:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function disabledthis(o) { o.disabled = "disabled"; __doPostBack(o.id, ""); } </script></head> <body> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Text="Button" /> <a href="#" onclick="<% =PostBack %>"></a> </div> </form> </body> </html> 后臺代碼: Protected PostBack As String = "" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load PostBack = ClientScript.GetPostBackEventReference(Button1, "") If Not IsPostBack Then Button1.Attributes.Add("onclick", "javascript:disabledthis(this);") End If End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Threading.Thread.Sleep(1000) End Sub
如
bool flag=false;
this.button.Enable=!flag;
http://www.oneclickbutton.de/index.php
aspx.cs中,button_clicked事件加入:
hfDisabledButton.Value = btn.ID;
在page_load中加入:
Button b = (Button)FindControl(Request["ctl00$cpMain$ctl00$hfDisabledButton"]);
if (b != null)
{
b.Enabled = false;
b.Style.Value = "color:#999999;";
}
以后再有postback事件也不会让button重新enable。
http://www.cnblogs.com/Jinglecat/archive/2007/07/10/811946.html#821900
無效的...他是在一個過程中,沒有POST到客戶端的,這個時候還是可以點擊的.
其實很簡單,用JAVASCRIPT來實現啊,
第一種方法:在onclick事件中綁定把自己disabled
前端頁面:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script type="text/javascript">
function disabledthis(o) {
o.disabled = "disabled";
__doPostBack(o.id, "");
}
</script></head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<a href="#" onclick="<% =PostBack %>"></a>
</div>
</form>
</body>
</html>
后臺代碼: Protected PostBack As String = "" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PostBack = ClientScript.GetPostBackEventReference(Button1, "")
If Not IsPostBack Then
Button1.Attributes.Add("onclick", "javascript:disabledthis(this);")
End If
End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Threading.Thread.Sleep(1000)
End Sub
樓主是要不讓用戶點...
完全已经实现你要的了啊... 还有第二种方法,就是使用一个隐藏的层,当点按键的时候把这个隐藏层显示出来并覆盖掉当前的页面,等程式Postback完毕,隐藏层又会消失掉
之所以我使用一個<a>的標記,是為了讓前端有 __doPostBack Function 的 JS,你也可以自己寫的,不過不推薦而已
前端:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script type="text/javascript">
function ScreenWaiting() {
var o;
var x, y;
x = screen.availWidth;
y = screen.availHeight;
o = document.getElementById("pWaiting");
o.style.width = x;
o.style.height = y;
o.style.visibility = "visible";
o.style.top = 0;
o.style.left = 0;
o.getFoucs;
}
</script> <style type="text/css">
.snake
{
background: Silver;
filter: alpha(opacity=50); /*IE*/
-moz-opacity: 0.5; /*MOZ , FF*/
opacity: 0.5; /*CSS3, FF1.5*/
position: absolute;
visibility: hidden;
text-align: center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 300px; width: 300px; border: solid 1px blue">
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
</form>
<div id="pWaiting" class="snake">
<center>
<p>
Processing... ...
</p>
</center>
</div>
</body>
</html>后臺:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Button1.Attributes.Add("onclick", "javascript:ScreenWaiting();")
End If
End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Threading.Thread.Sleep(3000)
End Sub
完畢,我提及的兩種方法都是Javascript實現的
思路:在提交的时候调用js代码将页面属性visibility:hidden;同时调用一个 “正在操作中,请稍后。。”的等待效果
当后台执行完成后,会自动刷新页面,js代码自动失效,以前的页面再次重现
那是用ajax处理的,异步交互成功后把层去掉
JS:
function CheckOnce(btn)
{
if(typeof(Page_ClientValidate) == 'function')
{
if (Page_ClientValidate() == false)
{ return false; }
}
if (btn.getAttribute('type') == 'button')
{
btn.disabled = true;
}
return true; }
然后 Click事件里面 写 System.Threading.Thread.Sleep(1000);然后 button有几个属性要注意一下<asp:button id="btnSave" Text='<%#ResourceMng.GetResource("ASP-M.969660")%>' CssClass="button" Runat="server" onclick="btnSave_Click"
UseSubmitBehavior="false" OnClientClick="CheckOnce(this)" ValidationGroup="SubgurimTest">
</asp:button>