防止多次提交的方法
a.aspx
<title>无标题页</title>
<style type="text/css">
.disable
{
border-style:none;
border-width: thin;
background-color:Transparent;
color: #CCCCCC;
cursor:wait;
}
</style>
<script type="text/javascript" language="javascript">
function DisableButton()
{
document.getElementById("Button2").className = "disable";
document.getElementById("Button2").value = '正在提交.';
document.getElementById("Button2").onclick=Function("return false;");
//return true;
}
document.onkeydown=mykeydown;
function mykeydown()
{
if(event.keyCode==116) //屏蔽F5刷新键
{
window.event.keyCode=0;
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="doing" style="Z-INDEX: 12000; visibility:hidden; LEFT: 0px; WIDTH: 100%; CURSOR: wait; POSITION: absolute; TOP: 0px; HEIGHT: 100%">
<table style="width:100%; height:100%;">
<tr align="center" valign="middle">
<td>
<table width="169" height="62" bgcolor="#99cccc" style="FILTER: Alpha(Opacity=75); WIDTH: 169px; HEIGHT: 62px">
<tr align="center" valign="middle">
<td>页面提交中.<br/>
Loading.</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<div>
<div>
输入一些内容<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:ListBox ID="ListBox1" runat="server" Height="77px" Width="332px"></asp:ListBox><br />
<asp:Button ID="Button2" runat="server" Text="OK" Width="77px" OnClick="Button2_Click" OnClientClick="return DisableButton();" />
<asp:Button ID="btnSumbit" runat="server" UseSubmitBehavior="false" OnClientClick="this.value='Sumbit';this.disabled=true; " Text="Sumbit" OnClick="btnSumbit_Click" />
<asp:Button ID="Button1" runat="server" Text="Loading" OnClick="Button1_Click1" />
</div>
</div>
</form>
</body>
</html>
a.aspx.cs
public partial class WebForm1 : System.Web.UI.Page
{
static public int count = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Button2.Attributes.Add("onclick", "return DisableButton();");
this.Button1.Attributes.Add("onclick", "javascript:document.getElementById('doing').style.visibility='visible';");
}
}
//override protected void OnPreRender(EventArgs e)
//{
// doing.Style.Add("visibility", "hidden");
//}
//override protected void OnPreRenderComplete(EventArgs e)
//{
// doing.Style.Add("visibility", "hidden");
//}
protected void Button2_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
count++;
ListBox1.Items.Add(new ListItem("Hello "+TextBox1.Text + " 这是你第" + count.ToString() + "次点击 " + DateTime.Now.ToString()));
TextBox1.Text = "";
}
protected void btnSumbit_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
count++;
ListBox1.Items.Add(new ListItem("Hello " + TextBox1.Text + " 这是你第" + count.ToString() + "次点击 " + DateTime.Now.ToString()));
TextBox1.Text = "";
}
protected void Button1_Click1(object sender, EventArgs e)
{
// doing.Style.Add("visibility", "show");
System.Threading.Thread.Sleep(3000);
}
}