前台代码:
<asp:Button ID="Button1" runat="server" Text="打印" onclick="Button1_Click" OnClientClick="this.value='数据提交中……';this.disabled=true;" UseSubmitBehavior="False" />
后台代码:
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中避免重复提交和弹出提示框的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对呐喊教程网站的支持!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。