防止在服务器处理完成之前用户多次点击提交按钮
1、在webform3.aspx中代码如下:
<%@ Page Language="c#" Codebehind="WebForm3.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication1.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>WebForm3</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.1" />
<meta name="CODE_LANGUAGE" content="C#" />
<meta name="vs_defaultClientScript" content="JavaScript" />
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5" />
<script type="text/jscript" language="javascript">
function abc()
{
var mybutton=document.getElementById("Button1");
mybutton.disabled=true; //变灰
__doPostBack("Button1",""); //执行服务器端button1的click事件
}
</script>
</head>
<body ms_positioning="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox ID="TextBox1" Style="z-index: 101; left: 8px; position: absolute; top: 8px"
runat="server"></asp:TextBox>
<asp:Button ID="Button1" Style="z-index: 102; left: 8px; position: absolute; top: 40px"
runat="server" Text="Button"></asp:Button>
</form>
</body>
</html>
AutoEventWireup="false" Inherits="WebApplication1.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>WebForm3</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.1" />
<meta name="CODE_LANGUAGE" content="C#" />
<meta name="vs_defaultClientScript" content="JavaScript" />
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5" />
<script type="text/jscript" language="javascript">
function abc()
{
var mybutton=document.getElementById("Button1");
mybutton.disabled=true; //变灰
__doPostBack("Button1",""); //执行服务器端button1的click事件
}
</script>
</head>
<body ms_positioning="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox ID="TextBox1" Style="z-index: 101; left: 8px; position: absolute; top: 8px"
runat="server"></asp:TextBox>
<asp:Button ID="Button1" Style="z-index: 102; left: 8px; position: absolute; top: 40px"
runat="server" Text="Button"></asp:Button>
</form>
</body>
</html>
2、在webform3.aspx.cs中主要两个方法中的代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
/*这句很关键,有这句才能让客户端执行服务器端事件。
VS2003环境可以不写 */
this.GetPostBackEventReference(Button1);
Button1.Attributes.Add("onclick","abc();");
}
{
/*这句很关键,有这句才能让客户端执行服务器端事件。
VS2003环境可以不写 */
this.GetPostBackEventReference(Button1);
Button1.Attributes.Add("onclick","abc();");
}