Asp.Net中避免重復提交和彈出提示框的實例代碼。本站提示廣大學習愛好者:(Asp.Net中避免重復提交和彈出提示框的實例代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是Asp.Net中避免重復提交和彈出提示框的實例代碼正文
前台代碼:
<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中避免重復提交和彈出提示框的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對網站的支持!
[db:作者簡介][db:原文翻譯及解析]