前台代码:
1
|
<asp:Button ID= "Button1" runat= "server" Text= "打印" onclick= "Button1_Click" OnClientClick= "this.value='数据提交中……';this.disabled=true;" UseSubmitBehavior= "False" />
|
后台代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
public partial class WebForm1 : System.Web.UI.Page
{
protected override void OnLoad(EventArgs e)
{
StringBuilder pageBase_script = new StringBuilder( "<script Language=\"Javascript\">" );
pageBase_script.Append( @"var times=0;
function pageBase_tick() //用于显示执行的时长
{
times++;
var str = '';
var temp = times%5;
for(var i=0;i<temp;i++)
str+='.';
document.getElementById('pageBase_Clocktimes').innerHTML ='正在提交,请稍候'+ str;
} "
);
pageBase_script.Append( "<" ).Append( "/" ).Append( "script>" );
StringBuilder pageBase_div = new StringBuilder( " <div id=\"pageBase_runing\" runat=\"server\" style=\"z-index: 12000; left: 0px; width: 100%; position: absolute; top: 0px; height: 100%\">" );
pageBase_div.Append( "<table width=\"100%\" height=\"100%\">" );
pageBase_div.Append( "<tr align=\"center\" valign=\"middle\">" );
pageBase_div.Append( "<td>" );
pageBase_div.Append( " <table width=\"200\" height=\"25\" bgcolor=\"#9999FF\" style=\"filter: Alpha(Opacity=70); \">" );
pageBase_div.Append( " <tr align=\"center\" valign=\"middle\">" );
pageBase_div.Append( " <td>" );
pageBase_div.Append( "<div style=\"width:200px;height:25px; background-color: #99CCFF; \">" );
pageBase_div.Append( " <div id=\"pageBase_Clocktimes\" style=\"color: #FF0000; float:left; width:196px;height:21px \" >正在提交,请稍候</div>" );
pageBase_div.Append( "</div>" );
pageBase_div.Append( "</td>" );
pageBase_div.Append( " </tr>" );
pageBase_div.Append( " </table>" );
pageBase_div.Append( " </td>" );
pageBase_div.Append( " </tr>" );
pageBase_div.Append( " </table>" );
pageBase_div.Append( "</div>" );
StringBuilder pageBase_divHide = new StringBuilder( "<script Language=\"Javascript\">" );
pageBase_divHide.Append( "document.getElementById('pageBase_runing').style.visibility = \"hidden\";" );
pageBase_divHide.Append( "<" ).Append( "/" ).Append( "script>" );
if (!Page.ClientScript.IsStartupScriptRegistered( "runingscript" ))
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "pageBase_div" , pageBase_div.ToString());
Page.ClientScript.RegisterStartupScript(Page.GetType(), "pageBase_script" , pageBase_script.ToString());
Page.ClientScript.RegisterStartupScript(Page.GetType(), "pageBase_divHide" , pageBase_divHide.ToString());
}
base .OnLoad(e);
}
/// <summary>
/// 设置提交之后.出现请等待提示,在页面调用基类的这个方法,把要提交的控件传入即可
/// </summary>
/// <param name="btn">提交按钮</param>
public void SubmitLoad(Button btn)
{
btn.Attributes.Add( "onclick" , "javascript:document.getElementById('pageBase_runing').style.visibility='visible';window.setInterval('pageBase_tick()',500);" );
}
/// <summary>
/// 设置提交之后.出现请等待提示
/// </summary>
/// <param name="lbtn">提交按钮</param>
public void SubmitLoad(LinkButton lbtn)
{
lbtn.Attributes.Add( "onclick" ,
"javascript:document.getElementById('pageBase_runing').style.visibility='visible';window.setInterval('pageBase_tick()',1000);" );
}
protected void Page_Load( object sender, EventArgs e)
{
SubmitLoad(Button1);
}
protected void Button1_Click( object sender, EventArgs e)
{
Button1.Enabled= false ;
//string IP = PrintingLabel.SearchPrinterIP(TextBox1.Text, TextBox2.Text, TextBox3.Text);
//Response.Write(IP);
int ifs=0;
for ( int i = 0; i < 1000000000; i++)
{
ifs++;
}
}
}
}
|
以上所述是小编给大家介绍的asp.net中避免重复提交和弹出提示框的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://www.cnblogs.com/qiuweiguo/archive/2012/10/18/2728837.html